use of java.util.concurrent.DelayQueue in project intellij-community by JetBrains.
the class LightPlatformTestCase method checkJavaSwingTimersAreDisposed.
private static void checkJavaSwingTimersAreDisposed() throws Exception {
Class<?> TimerQueueClass = Class.forName("javax.swing.TimerQueue");
Method sharedInstance = ReflectionUtil.getMethod(TimerQueueClass, "sharedInstance");
Object timerQueue = sharedInstance.invoke(null);
DelayQueue delayQueue = ReflectionUtil.getField(TimerQueueClass, timerQueue, DelayQueue.class, "queue");
Delayed timer = delayQueue.peek();
if (timer != null) {
long delay = timer.getDelay(TimeUnit.MILLISECONDS);
String text = "(delayed for " + delay + "ms)";
Method getTimer = ReflectionUtil.getDeclaredMethod(timer.getClass(), "getTimer");
Timer swingTimer = (Timer) getTimer.invoke(timer);
text = "Timer (listeners: " + Arrays.asList(swingTimer.getActionListeners()) + ") " + text;
throw new AssertionFailedError("Not disposed java.swing.Timer: " + text + "; queue:" + timerQueue);
}
}
use of java.util.concurrent.DelayQueue in project hive by apache.
the class TestLlapTaskSchedulerService method testLocalityDelayTaskOrdering.
@Test(timeout = 10000)
public void testLocalityDelayTaskOrdering() throws InterruptedException, IOException {
LlapTaskSchedulerService.LocalityDelayConf localityDelayConf = new LlapTaskSchedulerService.LocalityDelayConf(3000);
ControlledClock clock = new ControlledClock(new MonotonicClock());
clock.setTime(clock.getTime());
DelayQueue<LlapTaskSchedulerService.TaskInfo> delayedQueue = new DelayQueue<>();
LlapTaskSchedulerService.TaskInfo taskInfo1 = new LlapTaskSchedulerService.TaskInfo(localityDelayConf, clock, new Object(), new Object(), mock(Priority.class), mock(Resource.class), null, null, clock.getTime());
clock.setTime(clock.getTime() + 1000);
LlapTaskSchedulerService.TaskInfo taskInfo2 = new LlapTaskSchedulerService.TaskInfo(localityDelayConf, clock, new Object(), new Object(), mock(Priority.class), mock(Resource.class), null, null, clock.getTime());
delayedQueue.add(taskInfo1);
delayedQueue.add(taskInfo2);
assertEquals(taskInfo1, delayedQueue.peek());
}
use of java.util.concurrent.DelayQueue in project hadoop by apache.
the class TaskRunner method start.
@SuppressWarnings("unchecked")
public void start() {
if (executor != null) {
throw new IllegalStateException("Already started");
}
DelayQueue preStartQueue = queue;
queue = new DelayQueue();
executor = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 0, TimeUnit.MILLISECONDS, queue);
executor.prestartAllCoreThreads();
startTimeMS = System.currentTimeMillis();
for (Object d : preStartQueue) {
schedule((Task) d, startTimeMS);
}
}
Aggregations