Java Thread Pool Synchronization

I would like to perform the following algorithm - this must be done in Java

for(int i = 0; i< 100; i++){
    create 8 threads which perform a task
    wait for all threads to finish

It is desirable that threads are not continuously created and destroyed due to overheads (and the fact that each thread will have <20milli seconds of work), which brought about the idea of Thread Pools1. I also know that using Executable2, one can call shutdown, and then awaitTermination. However it is not desirable in this case due to the loop. Thus how can thread synchronization occur?

I would like to synchronize threads in the thread pool as would be done using a traditional thread's join() method.


Have you tried looking at a Cyclic Barrier. It is optimized to allow a group of threads to stop and wait till everyone has reached a common barrier. I can't seen any reason why it can't be used with known number of pooled threads with references to a common barrier. There could be some additional complexity if you need to synchronize on the callback invoked with the barriers await() count is reached because it executes in a different thread.

Need Your Help

sed token from : delimited string

regex shell sed token

I tried searching for an answer but lost in questions. Basically I have a shell script as follows:

notify_notification_new not showing icon

c libnotify

I'm completely stumped. I have this little thing to ease the mounting of MTP units under linux, but for some reason I can't get libnotify to show my icon when using variables. If I hardcode the com...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.