コード例 #1
0
ファイル: Exam.java プロジェクト: taoxie/Interview
 public static void main(String[] args) {
   Random r = new Random();
   DelayQueue<Student> students = new DelayQueue<Student>();
   ExecutorService exec = Executors.newCachedThreadPool();
   for (int i = 0; i < STUDENT_SIZE; i++) {
     students.put(new Student("学生" + (i + 1), 3000 + r.nextInt(9000)));
   }
   students.put(new Student.EndExam(12000, exec)); // 1200为考试结束时间
   exec.execute(new Teacher(students, exec));
 }
コード例 #2
0
ファイル: DelayQueueTest.java プロジェクト: FauxFaux/jdk9-jdk
 /** all elements successfully put are contained */
 public void testPut() {
   DelayQueue q = new DelayQueue();
   for (int i = 0; i < SIZE; ++i) {
     PDelay x = new PDelay(i);
     q.put(x);
     assertTrue(q.contains(x));
   }
   assertEquals(SIZE, q.size());
 }
コード例 #3
0
ファイル: DelayQueueDemo.java プロジェクト: jackode/most-java
 public static void main(String[] args) {
   Random rand = new Random(47);
   ExecutorService exec = Executors.newCachedThreadPool();
   DelayQueue<DelayedTask> queue = new DelayQueue<DelayedTask>();
   // Fill with tasks that have random delays:
   for (int i = 0; i < 20; i++) queue.put(new DelayedTask(rand.nextInt(5000)));
   // Set the stopping point
   queue.add(new DelayedTask.EndSentinel(5000, exec));
   exec.execute(new DelayedTaskConsumer(queue));
 }
コード例 #4
0
 public DelayedReply messageArrived(CellMessage envelope, PoolMgrGetUpdatedHandler message) {
   SerializablePoolManagerHandler handler = this.handler;
   UpdateRequest request = new UpdateRequest(envelope, message);
   requests.add(request);
   if (message.getVersion().equals(handler.getVersion())) {
     delays.put(request);
     UpdateRequest expired;
     while ((expired = delays.poll()) != null) {
       requests.remove(expired);
     }
   } else if (requests.remove(request)) {
     request.send(handler);
   }
   return request;
 }
コード例 #5
0
  public static void main(String[] args) throws InterruptedException {
    DelayQueue queue = new DelayQueue();

    DelayedObj element1 = new DelayedObj("1", 100);
    DelayedObj element2 = new DelayedObj("0", 1000);

    queue.put(element1);
    queue.put(element2);

    DelayedObj relement1 = (DelayedObj) queue.take();
    DelayedObj relement2 = (DelayedObj) queue.take();

    System.out.println(relement1.getLevel());
    System.out.println(relement2.getLevel());
  }
コード例 #6
0
 @Benchmark
 public VElement testSimpleDelayQueue() throws InterruptedException {
   simpleDelayQueue.put(new VElement("message"));
   return simpleDelayQueue.take();
 }
コード例 #7
0
 /** 请修改该方法,添加你的业务,修改参数,new */
 public void delay() {
   // 10s
   System.out.println("wwww");
   taskQueue.put(new LaogeDelayedTask(10 * 1000));
 }
コード例 #8
0
 public void addEvent(Event c) {
   c.start();
   q.put(c);
 }