• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Threads I need help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a program in which the thread pair implemented by the Kath and Rob classes work together.

The  Rob  class has a setInput (int x) method that allows you to set the value of the private int input field. In the run () method, it executes an infinite loop in which it checks the state of its break flag. When an interrupt request is detected, it reads the value of its input field:

- if set to 0, it prints a goodbye message and aborts;
- for another value, prints twice the input and continues.

The Kath  class executes a loop in the run () method and sends sequential numbers to the  Rob thread with the setInput () method, then waits 1 second. After sending the numbers from 1 to 10, it breaks the loop and sends the last value equal to 0, signaling the end of the calculation.

Tip. A  Rob  thread should check the interrupt request using interrupted () instead of isInterrupted (), since the former clears (resets) the interrupt flag in addition.

Main function


 
Saloon Keeper
Posts: 7161
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks like homework you should be doing in order to learn something. So: What do you have so far? If you haven't started, what ideas have you had?
 
Mer Ste
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea how to insert threads in Java and how to connect them together
 
Tim Moores
Saloon Keeper
Posts: 7161
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you learned about Thread? Presumably you would not be given an assigmnent like this without the subject having been covered in class before.
 
Marshal
Posts: 74341
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kindly don't edit posts like that after they have been replied to; I am refusing the changes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic