Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hi, I believe that your implementation is not the best you can do in this scenario. Your callable waits for exactly 1 second, but if there was a little bit of random, you will probably notice that the get() method, a blocking one, will slow down the execution in the for loop(because some of the results are not ready yet). Rewrite it using a while(!list.isEmpty()) block, every time you have a Future ready(use isDone()) you can safely get the result without delaying the execution and remove it from the list. HTH
- Silviu Burcea
All the tutorial are very Good and helpful. I want to run more than 1000 threads (Tasks) but not at a time may be 20 at a time using one of thread pools But I also want to cancel the task if it is blocked for more than 30 minutes. But that 30 minutes are not including submit times of the task. No more than 30 minutes should be used for execution. Is there any function for any class using that can put the maximum execution time? If yes will that function interrupt the thread that is executing the task? If yes then do we need to handle “ InterruptedException” for that thread? Please give your best suggestion and thanks for this good articles
- Agha Khan
Hi Pankaj, We normally pass a “User/Worker Thread instance” to the ThreadPoolExecutor/Scheduler but here the Callable Interface is not extending Runnable interface neither we are overriding any run() method. We are creating 100 callable instance but not thread, does it mean we cannot use callable for multi-threading purpose
- HIMANSU NAYAK
Hi Pankaj. One doubt regarding Callable interface. The compiler creates a synthetic method to invoke the call() method. Why is it required?
- Sayantan
Hi Pankaj, In my project we have one batch running more time. The scenario is one record getting from one database and inserting into another database. It is happening record by record. I want to execute these parallarly. In this case can I implement collable?
- ramesh
First of all, THANK YOU! A well written article and you explained the concepts so clearly. The code examples for marvelous! When is your book coming out? ;-) Russ
- Russ Ray