• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread pool implementation details like Executors.newCachedThreadPool  RSS feed

 
Ramya Chowdary
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

How to implement Thread Pool like the way java.util.concurrent.Executors.newCachedThreadPool implemented...( I want to know internals)

How come there won't be any IllegalThreadStateException if we are to reuse Threads again.....?






 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pratap koritala wrote:How to implement Thread Pool like the way java.util.concurrent.Executors.newCachedThreadPool implemented...( I want to know internals)


The source is available with the JDK, under a file name src.zip.

How come there won't be any IllegalThreadStateException if we are to reuse Threads again.....?


Technicallly, a thread doesn't call your runnable (or callable) task directly. Instead, the threads in the pool are running internal code, which are used to extract your tasks from the queue, and call your task's run() method. Once your tasks return from the run() method, the internal code will fetch the next task (or wait is there are no more tasks).

There are no thread restarts. And threads are *not* being reused.

Henry




 
Alan Mehio
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pratap koritala wrote:Hi ,

How come there won't be any IllegalThreadStateException if we are to reuse Threads again.....?




well, I can not see Thread reuse if you can see then please let me know.




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!