java - Is it possible to have a set of thread pools that share threads from a large thread pool instead of creating new thread? -
is possible have set of thread pools share threads large thread pool instead of creating new thread?
in our restful api application, request may involve several parallel tasks. improve performance, want execute parallel tasks in thread pool has fixed number (say 200) of threads. want limit max number of threads each request can use. thinking if possible create sub thread pool maximum pool size each request, not create thread tries fetch new thread global thread pool , put job queue if there no available threads.
has done similar? or there other better solution?
thanks!!
instead of thread pools, think of executors. executor consists of 2 things: job queue , thread pool. need light-weight executor each request has job queue has no threads. instead, passes jobs queue main executor (which owns threads). trick light-weight executor counts how many jobs has submitted main executor, , stops passing jobs when number exceeds limit. each job, before being passed main executor, wrapped in object of type runnable a) has reference parent light-weight executor, b) executes wrapped job , c) notifies referenced executor when job finished executor can pass job main executor (or decrease job counter, if there no jobs in queue).
Comments
Post a Comment