Last active
December 19, 2017 17:30
-
-
Save chathurangat/a291886712db80a455a96fa5969d0415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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