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

📄 producer.java

📁 java版ace,java程序员值得一看
💻 JAVA
字号:
//File: Producer.java//Seth Widoff 8/8/96//This class attempts at random intervals to enqueue random elements//into a queue. If the queue is full the thread waits until an element//has been dequeued and another thread has invoked the notify() method.package JACE.tests.Concurrency.Condition;import JACE.ASX.TimeValue;import java.lang.Math;import java.util.Random;public class Producer implements Runnable{  //Maximum pause between enqueues (in milliseconds)  private static final int MAX_PAUSE = 1000;    private SimpleMessageQueue queue_;  private boolean stop_requested_ = false;  private String name_;  private int iterations_;  private TimeValue timeout_;  public Producer(String name, 		  SimpleMessageQueue queue, 		  int iterations,		  TimeValue timeout)  {    name_ = "Producer " + name;    queue_ = queue;    iterations_ = iterations;    timeout_ = timeout;  }  public void run()  {    //Set the random number generator seed to the current time in milliseconds.    Random random = new Random(System.currentTimeMillis());    int element = 1;        for (int i = 0; i < iterations_; )      {	try	  {	    //	    element = random.nextInt();	    TimeValue absTv = TimeValue.relativeTimeOfDay (timeout_);	    queue_.enqueue((Object)new Integer(element), absTv);	    System.out.println("Producer::run() " + name_ 			     + " enqueued " + element +			       " Queue size: " + queue_.size());	    	    Thread.sleep(Math.abs (random.nextLong()) % MAX_PAUSE);	    i++;	    element++;	  }	catch(Exception excp)	  {	    System.out.print("Producer::run() Exception: ");	    System.out.println(excp);	  }      }  }  public void requestStop()  {    stop_requested_ = true;  }}

⌨️ 快捷键说明

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