cubbyhole.java

来自「this code is a parallel programming code」· Java 代码 · 共 37 行

JAVA
37
字号
/* =========================================================    CubbyHole   CubbyHole is a synchronized storage location for a single   value of type Object.    CubbyHole has two methods. Put and Get. Both are   synchronized so one cannot run whilst other threads are   running synchronized methods (i.e. Put and Get) within   this Object.    ========================================================= */public class CubbyHole{  private Object contents;  /* ==========================================================      Method for getting an Object from the buffer     ==========================================================  */  public synchronized Object get() {    return contents;  }  /* ==========================================================     Method for putting object into buffer     ==========================================================  */  public synchronized void put(Object value) {    contents = value;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?