… creating thread …

Learned this from Ed

DO NOT do this

for (int idx = 1; idx <= processors+1; idx++)
{
   new Thread(tg,
              this.new SampleProcessorServiceThread(),
              "thread" + idx).start();
}
this.doWait();
 ...

Instead, DO it this way

Thread[] threads = new Thread[processors+1];
for (int idx = 1; idx <= processors+1; idx++)
{
   threads[idx-1] = new Thread(tg,
              this.new SampleProcessorServiceThread(),
              "thread" + idx);
    threads[idx-1].start();
}
for (int idx = 0; idx < processors; ++idx)
{
    try
    {
        threads[idx].join();
    }
    catch (InterruptedException e)
    {
        // Don't care
    }
 }
...

SPEAK / ADD YOUR COMMENT
Comments are moderated.

You must be logged in to post a comment.

Return to Top