主线程和子线程之间的通信没有子线程终止

主线程和子线程之间的通信没有子线程终止

问题描述:

我想在我的程序中添加几个主题。 但我不希望那些任务完成时终止。 我希望那些任务完成时让他们睡觉。   然后主线程将唤醒线程以执行下一个任务。  1. 
主线程如何在唤醒它以启动下一个任务时将参数传递给子线程?   一旦线程完成任务,如何在返回睡眠状态之前将返回值传递回主线程(无需终止)。  3. 
子线程如何告诉主线程在进入睡眠状态之前完成任务?

I want to have few threads in my program.  But I don't want those to terminate when there tasks are done.  i rather want those to sleep when the tasks are done.   Main thread will then wake up the thread for the next tasks.  1.  How can main thread can pass parameters to child thread while waking it up to start the next task?   Once thread has done task, how can it pass the return value back to main thread before going to sleep (without terminating).  3.  How can child thread tells main thread that it is done with the task before going to sleep?

我不希望线程终止,因为它们可以在自己的大对象上工作和数据库连接。 终止和启动每个任务的线程将是非常昂贵的。   

I do not want threads to terminate as they will work on their own big objects and database connections.  terminating and starting thread for each task would be very costly.  

也许你正在寻找这个 - -
线程池

Perhaps you are looking for this -- Thread Pools