• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

a multithreaded program by creating a subclass of Thread

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want The threads will execute the following output in the suitable interface.

like this OUTPUT

thread1: Java
thread1: is
thread2: Java
thread1: an
thread2: is
thread1: exciting
thread2: an
thread1: new
thread2: exciting
thread1: language
thread1: for
thread1: concurrent
thread2: new
thread1: programming.
thread2: language
thread2: for
thread2: concurrent
thread2: programming.



but mine not display like that output
why ?


My output :

thread1: Java
thread2: Java
thread2: is
thread1: is
thread2: an
thread1: an
thread2: exciting
thread1: exciting
thread2: new
thread2: language
thread2: for
thread2: concurrent
thread1: new
thread2: programming
thread1: language
thread1: for
thread1: concurrent
thread1: programming




 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is your problem with the output? The first thing you should realize is that you should not be worrying about any one single order. The threads are running concurrently so the order can come out in any pattern. It looks like you expected intermingling, and you get intermingling. So I am not exactly sure where the problem is. Can you please explain what in the output you don't expect?
 
fazae vain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my assignment from my lecturer,she want excactly like her output. i know the thread will come out randomly -_- thats why i dont understand.


thread1: Java
thread1: is
thread2: Java
thread1: an
thread2: is
thread1: exciting
thread2: an
thread1: new
thread2: exciting
thread1: language
thread1: for
thread1: concurrent
thread2: new
thread1: programming.
thread2: language
thread2: for
thread2: concurrent
thread2: programming.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ask your professor to clarify the requirement. You can make it get the output she wants exactly, but it is a lot of synchronizing work and may not be what she actually wants.

If it is what she wants then you have to:
- Determine which thread you are in
- Compare the current word with the words that this thread should yield to the other thread.
- Use a synchronization token to notify the other thread
- Wait on the same synchronization token
 
fazae vain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay i'll tq steve
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic