• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread pool: Notifier or Listener  RSS feed

 
Arup Kumar Kabi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make a thread pool
so the design goes like this
A thread pool, will manage lot of activities of thread
like how many threads are there in the pool, which is active, giving a thread handle to a task etc.
but after the thread has finished the task
That is where I have a dilemma

I am not able to think whether to associate a notifier with the Thread
in that case Thread itself communicates saying I'm done with the task
or a Listener
which would check which thread is done and which is active etc. and notify the thread pool
both of them have their own complexity and I am not able to choose one
any thoughts....
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to have a look at how the ThreadPoolExecutor thread pool works in the standard Java library. It's been very carefully designed by smarter people than me.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I totally agree with Carey's advice, I would still like to answer your question.

Actually, in a threadpool it is far more easier if your thread runs continuously and polls a work queue for tasks.
If you get into an entity that hands over work after choosing a relevant thread, you will be addressing an unnecessary issue.
 
Arup Kumar Kabi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Nishant & Carey thanks a lot for the pointers.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!