sharedobject.java

来自「java 完全探索的随书源码」· Java 代码 · 共 27 行

JAVA
27
字号
public class SharedObject{  // The private shared data variable  private Integer sharedData = null;  // Default Constructor  public SharedObject( int initialValue )  {    super();    // Initialize the shared object value to something    sharedData = new Integer( initialValue );  }  // The produced will call this method to update the data  public synchronized void setSharedData( int newData )  {    System.out.println( "Shared Object - New Value Set: " + newData );    sharedData = new Integer( newData );  }  // The consumer will call this method to get the new data  public synchronized Integer getSharedData()  {    return sharedData;  }}

⌨️ 快捷键说明

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