0

I have a producer and consumer program implemented in Java. I would like to know how I can make the user type in "start" to start a new set of producer and consumer threads and type in "stop" to stop all the threads.

public static void main(String[] args) {
    BoundedBuffer bb = new BoundedBuffer(buffer size: 5, producers: 10, consumers: 1);
    bb.start();
Prog101
  • 109
  • 2
  • 10
  • You can just set a flag to stop producers and consumers. Also `Thread.interrupt()` is commonly used to stop threads. – markspace Nov 22 '19 at 00:52
  • The requirement is that the user has to type in start and stop. I wanted to know if there is a way to do this. – Prog101 Nov 22 '19 at 00:59
  • Wrap the following in a while True loop https://stackoverflow.com/questions/6032118/make-the-console-wait-for-a-user-input-to-close Inside the loop perform the action depending on the input. – v.tralala Nov 22 '19 at 02:33

0 Answers0