- 论坛徽章:
- 0
|
请问哪位有线程池的实现例子?
刚才查阅了一下,确有其事, 究竟是哪种理论正确。不知是否有人做过实验?不知版主是否能给出个权威答案?
SUN文档的原文如下:
Creating and Using Threads
The threads packages will cache the threads data structure, stacks, and LWPs so that
the repetitive creation of unbound threads can be inexpensive.
Unbound thread creation has considerable overhead when compared to process
creation or even to bound thread creation. In fact, the overhead is similar to unbound
thread synchronization when you include the context switches to stop one thread
and start another.
So, creating and destroying threads as they are required is usually better than
attempting to manage a pool of threads that wait for independent work.
A good example of this is an RPC server that creates a thread for each request and
destroys it when the reply is delivered, instead of trying to maintain a pool of
threads to service requests.
While thread creation has less overhead compared to that of process creation, it is
not efficient when compared to the cost of a few instructions. Create threads for
processing that lasts at least a couple of thousand machine instructions. |
|