⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writearray.java

📁 There is a shared object – int array[] between Write and Read. Write sets the array, Read gets the a
💻 JAVA
字号:
package cwq4;

import javax.swing.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class WriteArray extends Thread {
  private ArraySynchronized sharedArray;
  private int times;
  private JTextArea textarea;

  // initialize WriteArray thread object
  public WriteArray(ArraySynchronized shared, int x, JTextArea output) {
    super("Write Array Thread");
    sharedArray = shared;
    times = x;
    this.textarea = output;
  }

    // ProduceInteger thread loops x times and calls
    // sharedObject's setSharedArray method each time
  public void run(){

    for ( int count = 1; count <= this.times; count++ ) {
        // sleep for a random interval
        try {
          Thread.sleep( ( int ) ( Math.random() * 1000 ) );  }
        // process InterruptedException during sleep
        catch( InterruptedException exception ) {
          System.err.println( exception.toString() );  }

          // call sharedObject method from this thread of execution
          sharedArray.setSharedArray(textarea);
       }
    }
}// end class WriteArray

⌨️ 快捷键说明

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