Concurrency: Producer & Consumer
Implement correctly OneElementBuffer class to meet all the requirements
-
must synchronize NumberProducer with NumberConsumer
-
must store only one element at a time
-
stored element cannot be overwritten
-
stored element cannot be taken more than once
-
Producer produces end integer numbers from range [0, end)
-
Each produced value is placed in a buffer
-
Consumer consumes integer end numbers
-
Each consumed element is taken from a buffer one by one
To fix OneElementBuffer use synchronized and Thread.yield
To fix ModernOneElementBuffer use synchronized and wait/notify