• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayBlockingQueue with the ID  RSS feed

 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my main class in which I am trying to create a `ThreadPoolExecutor` with the given size.



Problem Statement:-

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.

Two Questions:-

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?



 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raihan Jamal wrote:This is my main class...

Raihan,

I broke up that very long line in your code. Please re-read the UseCodeTags page thoroughly, because I won't do it again.

Thanks

Winston
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

HIH

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