public void run() {
   try {
     while (!Thread.interrupted()) q.take().run(); // Run task with the current thread
   } catch (InterruptedException e) {
     // Acceptable way to exit
   }
   print("Finished DelayedTaskConsumer");
 }
 public void run() {
   try {
     while (true) {
       delayQueue.take().run();
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Exemple #3
0
 @Override
 public void run() {
   try {
     // 老师只负责看场子,考试结束后也是 Assistant 继续做事
     while (!Thread.interrupted()) {
       students.take().run();
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Exemple #4
0
 @Override
 public void run() {
   try {
     System.out.println("考试开始……");
     while (!Thread.interrupted()) {
       students.take().run();
     }
     System.out.println("考试结束……");
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
 public void run() {
   try {
     while (!Thread.interrupted()) {
       Event event = q.take();
       print(event);
       event.run();
     }
   } catch (InterruptedException e) {
     // Acceptable way to exit
   }
   print("Finished Controller");
 }
  /** Delayed actions do not occur until their delay elapses */
  public void testDelay() throws InterruptedException {
    DelayQueue<NanoDelay> q = new DelayQueue<NanoDelay>();
    for (int i = 0; i < SIZE; ++i) q.add(new NanoDelay(1000000L * (SIZE - i)));

    long last = 0;
    for (int i = 0; i < SIZE; ++i) {
      NanoDelay e = q.take();
      long tt = e.getTriggerTime();
      assertTrue(System.nanoTime() - tt >= 0);
      if (i != 0) assertTrue(tt >= last);
      last = tt;
    }
    assertTrue(q.isEmpty());
  }
 @Override
 public JobResult doRun() throws FastcatSearchException {
   while (!isCanceled) {
     try {
       SegmentDelayedClose segmentDelayedClose = segmentDelayCloseQueue.take();
       if (segmentDelayedClose != null) {
         segmentDelayedClose.closeReader();
       }
     } catch (Throwable e) {
       // ignore
     }
   }
   logger.info("Segment delay closer finished!");
   return new JobResult();
 }
  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());
  }
 @Benchmark
 public VElement testSimpleDelayQueue() throws InterruptedException {
   simpleDelayQueue.put(new VElement("message"));
   return simpleDelayQueue.take();
 }
Exemple #10
0
 /** toArray contains all elements */
 public void testToArray() throws InterruptedException {
   DelayQueue q = populatedQueue(SIZE);
   Object[] o = q.toArray();
   Arrays.sort(o);
   for (int i = 0; i < o.length; i++) assertSame(o[i], q.take());
 }
Exemple #11
0
 /** take retrieves elements in priority order */
 public void testTake() throws InterruptedException {
   DelayQueue q = populatedQueue(SIZE);
   for (int i = 0; i < SIZE; ++i) {
     assertEquals(new PDelay(i), q.take());
   }
 }