Question

We need to do some asynchronous task processing where in around 30-40 requests will be coming at the same moment and each request will intiate a asynch task which will approximately take around 7-8 seconds to complete.

If java executorservice has been identified to do such task, what would be the idle type of executor for such purpose?

I thought of using CachedThreadPool but my worry is if too many threads are created would it have any performance impact on the application?

Another option would be to use FixedThreadPool but I am struggling to think of a idle no threads which it should be instantiated with... What is the recommended Executor for such a scenario or how we go about finding the right one?

Was it helpful?

Solution 2

I thought of using CachedThreadPool but my worry is if too many threads are created would it have any performance impact on the application?

You need to test for the application for performance impact. If none of them fits into the application or having some issues then you can use customized thread pool executor java.util.concurrent.ThreadPoolExecutor

You can customize according your needs with configuiring core pool size, configuring the blocking queue. Blocking queue will be used and task will be queued when pool size is reached.

OTHER TIPS

I think you are limiting your research to just the Executors.* factory methods. You should review what the range of constructors of ThreadPoolExecutor, you'll find a maximum thread pool size limit, among other things.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top