Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2012, 09:44 AM   PM User | #1
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
What's the best way to have a specific amount of threads run and/or be reused?

So let's say I have an iterator it that returns something of class CustomClass. The iterator has "many" CustomClass to go over. More over, let's say that a user inputs something that makes my program decide only 5 threads can be running at any moment by my program.

In a way, something like this is expected to happen:
Code:
for(int i = 0; i < 5 && it.hasNext(); i++) {
  new Thread(it.next()).start();
}
Now, again only five are allowed and there are many more elements in the iterator. But after one thread is done with its run(), I want it to call it.next() and create a new thread. BUT the problem is that it is not defined in this thread. CustomClass doesn't even have a next() method of any kind. How would I make this work out so that each thread can "access" the iterator efficiently?
Apothem is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:34 AM.


Advertisement
Log in to turn off these ads.