GeneralMonitor - using synchronized methods and lambda threads
This commit is contained in:
25
GenericMonitor/src/GenericMonitor.java
Normal file
25
GenericMonitor/src/GenericMonitor.java
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
public class GenericMonitor {
|
||||
|
||||
static Buffer MyBuffer = new Buffer();
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
new Thread(() -> {
|
||||
System.out.println("Producer running");
|
||||
for ( int nn=0; nn < 20; nn++) {
|
||||
MyBuffer.Write( nn );
|
||||
System.out.println("Producer Wrote " + nn);
|
||||
}
|
||||
}).start();
|
||||
new Thread(() -> {
|
||||
System.out.println("Consumer running");
|
||||
for ( int nn=0; nn < 20; nn++ ) {
|
||||
System.out.println("Consumer Read " + MyBuffer.Read());
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user