< prev index next >

src/java.base/share/classes/java/util/concurrent/Exchanger.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2021-01
Reviewed-by: martin

*** 55,77 **** * buffer gets a freshly emptied one when it needs it, handing off the * filled one to the thread emptying the buffer. * <pre> {@code * class FillAndEmpty { * Exchanger<DataBuffer> exchanger = new Exchanger<>(); ! * DataBuffer initialEmptyBuffer = ... a made-up type ! * DataBuffer initialFullBuffer = ... * * class FillingLoop implements Runnable { * public void run() { * DataBuffer currentBuffer = initialEmptyBuffer; * try { * while (currentBuffer != null) { * addToBuffer(currentBuffer); * if (currentBuffer.isFull()) * currentBuffer = exchanger.exchange(currentBuffer); * } ! * } catch (InterruptedException ex) { ... handle ... } * } * } * * class EmptyingLoop implements Runnable { * public void run() { --- 55,77 ---- * buffer gets a freshly emptied one when it needs it, handing off the * filled one to the thread emptying the buffer. * <pre> {@code * class FillAndEmpty { * Exchanger<DataBuffer> exchanger = new Exchanger<>(); ! * DataBuffer initialEmptyBuffer = ...; // a made-up type ! * DataBuffer initialFullBuffer = ...; * * class FillingLoop implements Runnable { * public void run() { * DataBuffer currentBuffer = initialEmptyBuffer; * try { * while (currentBuffer != null) { * addToBuffer(currentBuffer); * if (currentBuffer.isFull()) * currentBuffer = exchanger.exchange(currentBuffer); * } ! * } catch (InterruptedException ex) { ... handle ...} * } * } * * class EmptyingLoop implements Runnable { * public void run() {
< prev index next >