• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

print m1 m2 m3 in 3 different threads in sequence

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi,
THe output Iam getting now is

Thread Name is = Thread M1 m1
Thread Name is =Thread M1 m2
Thread Name is =Thread M1 m3
Thread Name is = Thread M2 m1
Thread Name is =Thread M2 m2
Thread Name is =Thread M2 m3
Thread Name is = Thread M3 m1
Thread Name is =Thread M3 m2
Thread Name is =Thread M3 m3


However, I want thread2 to print m1 after thread 1 prints m1, and thread 3 to print m1 after thread 2.
I mean, the desired output is

m1 (code run by thread 1)

m1 (code run by thread 2)

m1 (code run by thread 3)

m2 (code run by thread 1)

m2 (code run by thread 2)

m2 (code run by thread 3)

m3 (code run by thread 1)

m3 (code run by thread 2)

m3 (code run by thread 3)

Thanks
Faisal
 
Faisal syed
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We cannot use join() as well since after thread 1, 2 and 3 print m1 in this order, they again need to print m2, m3.

Please advise.

Thanks
Faisal
 
author
Posts: 23909
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

If you need an exact sequence, then either consider doing it single threaded, or add enough share state so that a thread will only run when it is its turn only.

Henry
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic