• 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

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: 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

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
reply
    Bookmark Topic Watch Topic
  • New Topic