I would like to implement a thread pool in Java, which can dynamically resize itself based on the computational and I / O tasks presented to it.
In practice, I want to achieve the same behavior as the new thread pool implementation in C # 4.0
Is there an implementation already or can I achieve this behavior using mostly existing concurrency utilities (like CachedThreadPool)?
The C # version performs self-diagnostics to achieve optimal use. What native tools are available in Java and what are the real performance implications?
Is it possible to implement a cooperative approach when a task signals its intention (for example, entering into an intensive I / O operation, entering into an intensive working phase of the processor)?
Any suggestions are welcome.
Edit Based on comments:
Target scenarios may be:
- Local scanning and file processing
- Web Crawl
- Access and aggregate multiple web services
The problem with CachedThreadPool is that it starts new threads when all existing threads are blocked - you need to set explicit boundaries on it, but that is.
For example, I have 100 web services to access per line. If I create 100 CTPs, it will start 100 threads to complete the operation, and a ton of several I / O and data transfer requests will surely stumble onto each other's legs. For a static test case, I could experiment and find the optimal pool size, but I want it to be adaptively defined and applied in this way.
source share