2

Goal

I want to understand how to handle two thread pools simultaneously in java?


Consider a client server system in which clients are sending blocking I/O requests to the server (for example a file server ). There is a single ThreadPoolExecutor instance running on the server. Some types of client’s requests take much longer to process than other requests. These requests are called high I/O intensity requests. These high I/O intensity requests hog all threads and bring down entire application.


I want to solve this problem by two separate ThreadPoolExecutor. I create two ThreadPoolExecutor instances ,one for high I/o intensity requests and another for low I/o intensity requests, and through offline workload procedure I create a lookup table to classify requests and when a request arrive I first search its class in the lookup table so that I can handover it to its corresponding thread pool.


Real Problem. How to share processors equally to these two thread pools. Will this task be handled by JVM itself or I have to handle it by myself on application level ? Should I make use of cluster and use another machine that run an instance of ThreadPoolExecutor to handle high I/O intensity requests? Kindly give me proper design suggestions.

ahmad raza
  • 41
  • 3
  • You cannot decide how many resources are handled to threads, this is kernel decision, not yours (fortunately). But you can give priority to the threads. – m0skit0 Jan 24 '15 at 19:24
  • Have you looked a Prof Kabutz's [Striped Executor](http://www.javaspecialists.eu/archive/Issue206.html) - It looks like it would do what you need - or at least a variant of it may. – OldCurmudgeon Jan 24 '15 at 20:18

2 Answers2

0

Generally is up to the system CPU scheduler how to distribute time between threads. Thread pool has nothing to do with thread scheduling. It can manage some threads reusing or synchronization between them.

The only advantage of creating 2 pools instead of 1 is that one pool can use ThreadFactory different than standard Executors.defaultThreadFactory(). You can give different priority for your demanding clients. Prority is a information that scheBut they would suffer even more then if you make them less important or vice versa ;)

Maybe you could rather do something like tuning it's priority when someone uses too much resources.

Here is some reference how does Microsoft uses priorities to tune threads CPU consumption.

damienix
  • 6,463
  • 1
  • 23
  • 30
0

No the JVM cannot route the ThreadPoolExecutor for you. You may implement a external watcher thread that monitor your threads and apply the appropriate policy to them (priority, exception handling and so on).

Take a look at this example:

http://tutorials.jenkov.com/java-multithreaded-servers/thread-pooled-server.html

baymax
  • 151
  • 3