CircularBuffer: Nice buffer with lambda producer and consumer

This commit is contained in:
Karsten Jeppesen
2021-03-02 17:20:41 +01:00
parent d363a3e30a
commit ba6d58efb9
4 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
public class CircularBuffer {
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();
}
}