View Single Post
  #2   Spotlight this post!  
Unread 01-06-2012, 10:04
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: Concurrency and multiple commands

Concurrency.

Your for loop is completing and incrementing currentCommand before your threads are actually starting.

Despite calling thread.start() - they don't actually have to start "right away."

This is why you also never see "Running = 0".

When your 1st spawned thread finally runs, the for loop has already completed, and currentCommand was incremented to 1 before the thread even ran...

A hack fix would be to add a thread.join(???) at the end of your for loop (after thread.start(), where ??? is just long enough to start your Command.

Not pretty, but it'll likely work.

Even better, pass currentCommand as a parameter to your threads... something like:
http://stackoverflow.com/questions/8...-a-java-thread

Good luck!
__________________
In life, what you give, you keep. What you fail to give, you lose forever...

Last edited by Mr. Lim : 01-06-2012 at 10:08.
Reply With Quote