| Author |
Threads behave in sequential Style
|
sanjey asok
Ranch Hand
Joined: Jul 11, 2009
Posts: 36
|
|
I have a program which create many Thread and each one execute its process,
Among all threads ,one thread take more time(MyCallable1) to finish it process and other thread (MyCallable) take less time to finish its process,
I call the long-running Thread first and call others one by one ,but the other thread wait for the thread MyCallable1 to finish after that,It start it process.
Why other threads MyCallable wait for MyCallable1,then it is not real multithreaded?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
sanjey asok wrote:
Why other threads MyCallable wait for MyCallable1,then it is not real multithreaded?
How do you know this is happening? Your MyCallable don't print anything out. So, how do you know that they are actually waiting for MyCallable1 to finish?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
sanjey asok
Ranch Hand
Joined: Jul 11, 2009
Posts: 36
|
|
Henry Wong wrote:
sanjey asok wrote:
Why other threads MyCallable wait for MyCallable1,then it is not real multithreaded?
How do you know this is happening? Your MyCallable don't print anything out. So, how do you know that they are actually waiting for MyCallable1 to finish?
Henry
MyCallable return current time
After "Ending " printed ,every thread returns value
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
When I run your code, it seems to work correctly -- all threads are running concurrently.
One little aside: you don't call sleep on a specific Thread instance but rather call it as a static method,
This calls sleep on the current thread.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
sanjey asok wrote:
Henry Wong wrote:
How do you know this is happening? Your MyCallable don't print anything out. So, how do you know that they are actually waiting for MyCallable1 to finish?
MyCallable return current time
After "Ending " printed ,every thread returns value
You do know that the "current time" being returned, is for a time that was taken at the beginning of the method, right? So... all those times returned, are their start times, and not their end times. And since all the threads started around the same time, they should be close to each other.
Henry
|
 |
 |
|
|
subject: Threads behave in sequential Style
|
|
|