Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Last active December 19, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/a291886712db80a455a96fa5969d0415 to your computer and use it in GitHub Desktop.
Save chathurangat/a291886712db80a455a96fa5969d0415 to your computer and use it in GitHub Desktop.
import java.util.LinkedList;
import java.util.Queue;
public class Factory
{
private static Queue<String> sharedQueue = new LinkedList<>();
public static void main(String[] args)
{
System.out.println("factory started ");
Producer producer = new Producer(sharedQueue);
producer.start();
Consumer consumer = new Consumer(sharedQueue);
consumer.start();
try {
System.out.println("main thread wait until the consumer completes ");
synchronized (consumer) {
consumer.wait();
}
} catch (InterruptedException e) {
System.out.println("sleeping thread get interrupted ");
}
System.out.println("main thread completed ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment