View Single Post
  #4   Spotlight this post!  
Unread 01-06-2012, 14:11
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Concurrency and multiple commands

Quote:
It's possible you might be trying to re-invent something that already works pretty well!
Funny thing is that that is exactly what I'm trying to do.

Quote:
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.
I feel like that is not a sufficiently consistent way of doing what I am trying to do. (As well as almost eliminating the purposes of doing it - that will either not wait long enough or make the commands run in sequence (and not concurrently))

My biggest issue is that when I tried to do this :
Code:
    private void runConcurrentCommands(final Vector<CommandBase> v) {
        currentCommand = 0;
        Thread thread = null;
        System.out.println("Current = "+currentCommand);
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Running = "+currentCommand);
                CommandBase.getInstance().run(v.get(currentCommand));
                currentCommand++;
            }
        });
        thread.start();
    }
it did not change the output.

To me, that would eliminate the problem by only incrementing the commandCount AFTER the command has run (And not incrementing it beforehand on the first run).
__________________
All opinions are my own.
Reply With Quote