Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads behave in sequential Style

 
sanjey asok
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20993
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sanjey asok
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20993
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic