GeneralMonitor - using synchronized methods and lambda threads

This commit is contained in:
Karsten Jeppesen
2021-03-02 16:56:04 +01:00
parent 6c1a72cd70
commit 3f7dc9712c
4 changed files with 96 additions and 0 deletions

View 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();
}
}