Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Java Thread Pool - Executors

 
Ranch Hand
Posts: 431
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 5, executors framework was introduced having the concept of thread pools. We can create fixed size thread pool or cached thread pool etc. Suppose we create a thread pool of 10 threads and all threads are doing their tasks. The thread is started by calling the start method and once we call start method, so again start method can't be called on thread. But in thread pool, the threads go back to the pool after finishing their job and will pick up another task to work upon. So, how does it would be able to call start method again?
 
Saloon Keeper
Posts: 242
39
Firefox Browser MySQL Database Java Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a thread pool ExecutorService you don't call start on threads; in fact you don't ever touch the threads at all. The executor handles that. You just submit runnable or callable tasks to the ExecutorService and leave it to handle the task. To run the task again, you would have to submit it to the Executor again.
 
Vaibhav Gargs
Ranch Hand
Posts: 431
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks JJ Roberts.

The executor service won't be calling thread methods internally. I am new to these concepts so may be i am wrong. But I believe the underlying APIs such as thread.start etc. will be called or my understanding is not correct?
 
Jj Roberts
Saloon Keeper
Posts: 242
39
Firefox Browser MySQL Database Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Executor is an object designed to abstract executing a task from the actual mechanics of thread creation, invocation, etc. All you have to do is set up the appropriate Executor, and submit tasks. It will then give it to a thread (or threads) to run. You don't need to know the mechanics of what it actually does under the covers.
reply
    Bookmark Topic Watch Topic
  • New Topic