• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Threads behave in sequential Style

 
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?







 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
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
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
    Bookmark Topic Watch Topic
  • New Topic