forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumer.java
More file actions
28 lines (24 loc) · 681 Bytes
/
Copy pathConsumer.java
File metadata and controls
28 lines (24 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//file: Consumer.java
import java.util.Vector;
public class Consumer implements Runnable
{
Producer producer;
Consumer( Producer producer ) {
this.producer = producer;
}
public void run() {
while ( true ) {
String message = producer.getMessage();
System.out.println("Got message: " + message);
try {
Thread.sleep( 2000 );
} catch ( InterruptedException e ) { }
}
}
public static void main(String args[]) {
Producer producer = new Producer();
new Thread( producer ).start();
Consumer consumer = new Consumer( producer );
new Thread( consumer ).start();
}
}