I have to use Java ThreadPoolExecutor in one of my component in Android. I was searching the use of allowCoreThreadTimeout( ).
I have read the Java & Android docs related. But I didn't get any useful implementation scenario of the method. Can someone please help me??
The ExecutorService interface contains a large number of methods to control the progress of the tasks and manage the termination of the service. Using this interface, we can submit the tasks for execution and also control their execution using the returned Future instance.
ThreadPoolExecutor is an ExecutorService to execute each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods. It also provides various utility methods to check current threads statistics and control them.
CorePoolSize: The ThreadPoolExecutor has an attribute corePoolSize that determines how many threads it will start until new threads are only started when the queue is full. MaximumPoolSize: This attribute determines how many threads are started at the maximum. You can set this to Integer.
Call cancel() on the Future to Cancel a Task You can cancel tasks submitted to the ThreadPoolExecutor by calling the cancel() function on the Future object. Recall that you will receive a Future object when you submit your task to the thread pool by calling the submit() function.
Permitting core threads to timeout allows an application to efficiently handle 'bursty' traffic. Consider a scenario where an enterprise application is idle during business hours but receives a burst of many requests at the end of the day.
One way of efficiently handling this scenario would be to enable allowCoreThreadTimeout()
and set coreThreads
= maxThreads
to some appropriately high value. During that peak time your thread pool would scale up to handle the traffic and then afterwards scale back down to zero, freeing up server resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With