• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads behave in sequential Style

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic