This is my main class in which I am trying to create a `ThreadPoolExecutor` with the given size.
Previously I was using the concept of LinkedList here to pass the unique ID everytime and release that id for reuse by the threads. But somehow that was not working properly when I tested that out.
As I need-
Each thread should use unique ID between 1 and 500 and program has to run for 60 minutes or more, So in that 60 minutes it is possible that all the ID's will get finished so I need to reuse those ID's again.
So Now I started using the concept of ArrayBlockingQueue which I tested it out slightly and it was looking good to me. But just wanted to make sure, I am doing right and this program will not crash in any of the case, I needed some help.
1) Is there any other better approach than this considering my above scenario?
2) Secondly is there any loop hole in my program considering my above scenario as each thread needs to use UNIQUE ID everytime and release those ID's for reuse?
Raihan Jamal wrote:This is my main class in which I am trying to create a `ThreadPoolExecutor` with the given size.
I'm not quite sure what you're asking. Is this simply an exercise to understand how pools work, or do you actually want to create a fixed-size Pool? Because if so, I suggest you look at Executors.newFixedThreadPool().
If it's just an exercise, it sounds like you're on the right track, but you also need a facility for removing finshed Threads from the Queue to a "Pool" somewhere (which could be pretty much any sort of Collection; just set it up with the 500 Threads or Runnables (my preference) you intend to run).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
The only taste of success some people get is to take a bite out of you. Or this tiny ad: