Many threads on multiple processors
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bob_Looney
Posted On:   Friday, January 18, 2002 08:55 AM

I'm looking for a way to find out when all of my threads have finished processing. I have several different implementations that work on a single processor machine such as... inst is an array of 1000+ threads for (i = 0;i inst[i].start() for (i = 0;i inst[i].join(); however this never terminates on a multiprocessor machine. I've also tried an isAlive loop instead of join that waits until all threads have terminated until it goes on. Again, this works on the single processor but not the multi-processor machine. The functionality I'm aiming for is to kickoff a thread after receiving data on a socket that does a bunc   More>>

I'm looking for a way to find out when all of my threads have finished processing. I have several different implementations that work on a single processor machine such as...



inst is an array of 1000+ threads


			
for (i = 0;i
inst[i].start()

for (i = 0;i
inst[i].join();


however this never terminates on a multiprocessor machine. I've also tried an isAlive loop instead of join that waits until all threads have terminated until it goes on. Again, this works on the single processor but not the multi-processor machine.


The functionality I'm aiming for is to kickoff a thread after receiving data on a socket that does a bunch of math processing in parallel so that no request takes overly long to return which it would in a serial implementation, instead all are slightly slower (yes, i realized i just explained parallelism, sorry). I need to time the worst case of 1000(+) requests (threads) needing to execute at the same time. I do a System.currentTimeMillis (); before the processing starts and I need to do another one after the processing ends. however, the multi-processor machines seem to never finish one or more threads. There are no deadlocks occuring. I've thought of creating an array of objects that each call wait and then notify from each thread when I'm done. This seems like a ton of overhead though, but if it's the only way then it's the only way.


Additionally if anyone knows of a resource that explains how the sun JVM for solaris and Win32 function on multiple processors for calls like Thread.isAlive, Thread.join, etc. I'd appreciate it.

   <<Less

Re: Many threads on multiple processors

Posted By:   Anonymous  
Posted On:   Saturday, January 19, 2002 03:29 PM

Have you tried putting your worker threads in a ThreadGroup and then check that ThreadGroup's active thread count?

You could then make something like this:


while ( threadGroup.activeCount ( ) ) {

try {

Thread.currentThread.sleep ( 10 );

} catch ( InterruptedException e ) { }

}


This is a safe way to hold an eye on the active thread count for one job. If you would just use Thread.activeCount ( ), you could get 'influenced' by other thread-spawning threads!


Hope this helps ...



Regards,


G√ľnther.

http://www.javacoding.net

Re: Many threads on multiple processors

Posted By:   Christopher_Schultz  
Posted On:   Friday, January 18, 2002 11:56 AM

That's unusual that your join() solution does not work.



Try looking in the Java bug database for similar problems.



-chris

Re: Many threads on multiple processors

Posted By:   Jordan_Zimmerman  
Posted On:   Friday, January 18, 2002 09:05 AM

Why not create a little counter class that has a count of all the active threads. Your main thread can synchronize on it and wait(). Then, as each thread completes, it would synchronize on the counter, decrement it and call notifyAll(). Once the main thread sees that the count is 0, you know all the threads are done.
About | Sitemap | Contact