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 Pankaj, Thanks for article. Well, for all of them… keep up good work. Anyway, one thing bothers me. Why not to use submit(Callable) instead? Is this solution has some benefits i can not see now? Cheers.
- Josiash
Bydefault, Future task is run asynchronously , so will be executed in a different Thread from the one which added it by calling the execute method. For example " Thread1" called execute method , Futuretask will be executed in “Thread2”. Thread1 can get the result by calling " get" method of Futuretask it passed. On the other hand , callable by default will be executed on same Thread , unless you are using custom executor that starts a new thread. If " Thread1" submitted callable, the callable will be run on Thread1, unless the executor you are using spawns a new thread and run the callable in that thread Look at AsyncTask in android, attribute " mWorker" is a callable , which then is passed into “mFuture” which is a Future task… It is the Futuretask which will be passed to ThreadPoolExecutor., so future task executes asynchronously in another thread - the mWorker that it has. One more thing mWorker does is it makes the thread in which it is running a background thread as well.
- H
Here in the above example we are implementing callable and passing it to execute(). execute() only accepts Runnable,so i think you should be using submit() here.
- Shivam
Nice article… good job. Just one thing about this web site -You have a very annoying popup ( FREE eBook… ) on your web page, which cannot be closed due to over-lapping share-bar. Please get rid of this…
- Shashi
Hi, i am using above code, my thread run only once i want execute continues with 1 sec delay…
- Nikhil
hi , i am usimg above code by creating inner class, but task execute at once only not continuesly execute, i want execute continuesly with 1 sec delay…
- Nikhil
Hello Thank you for a wonderful series of tutorials on Executor framework. May I ask two basic questions regarding this tutorial: 1. why on the 2nd example ‘while (true)’ is needed? what changes if we skip it? 2. what does futureTask1.get() / futureTask2.get() return ? isn’t it callable1.call() / callable2.call() ? if so, why why we output futureTask1.get() in negation if(!futureTask1.isDone())? what do we expect to ‘get’ when the task did not finish yet? Thank you
- Andrey
Would you please show the usage of overloaded submit(Runnable, T) method.
- Pran