Java Code To create N threads till the List is empty

R

Ravi

Hi,

I have a list Containing Domain Names(Example-domainList)
I have a method to get information for each
domain(Example-readDomainInfo(string domainName))

I need java code to create N threads(Example-N=5). All N threads
should be running at a time to get information for each domain in list
by calling readDomainInfo() until all the domains in the list are
complete.

Please provide me the code for above requirement.

Regards
Ravi
 
C

Christophe Vanfleteren

Ravi said:
Hi,

I have a list Containing Domain Names(Example-domainList)
I have a method to get information for each
domain(Example-readDomainInfo(string domainName))

I need java code to create N threads(Example-N=5). All N threads
should be running at a time to get information for each domain in list
by calling readDomainInfo() until all the domains in the list are
complete.

Please provide me the code for above requirement.

Wow, you're kind of lazy, aren't you?
 
G

Gordon Beaton

I need java code to create N threads(Example-N=5). All N threads
should be running at a time to get information for each domain in
list by calling readDomainInfo() until all the domains in the list
are complete.

Please provide me the code for above requirement.

Please do my homework for me, while I waste my 4-5 years at
university. Then please do my job for me, because I am not capable of
doing it myself.

/gordon
 
J

JavaJug

Please provide me the code for above requirement.
public class IAmNotALazyBoy implements Runnable {
Vector threads;

public IAmNotALazyBoy () {
threads = new Vector();

threads.add( new Thread( iDontDeleguateMyWorkOnOtherPeople ) );
threads.add( new Thread( iReadTheJavaDocumentation ) );
threads.add( new Thread( iReadMyProblemSpecificDocumentation ));
threads.add( new Thread( iTryToSolveTheProblemByMyself ) );
}

public solveTheProblem() {
for (int i = 0; i < threads.size(); i++) {
treads.start();
}

boolean solved = false;
while( !solved ) {
solved = true;
for (int i=0; i<threads.size(); i++) {
solved = solved && (! threads.isAlive());
}
}
}

public static void main(String[] aargh) {
IAmNotALazyBoy ianalb = new IAmNotALazyBoy();
ianalb.solveTheProblem();
System.out.println("Problem solved !");
}
}

This code can be applied to all kind of problem, this is the one I use
most of the time.

Xav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top