use of jgnash.engine.concurrent.PriorityThreadPoolExecutor in project jgnash by ccavanaugh.
the class AbstractJpaDAO method shutDownExecutor.
static void shutDownExecutor() {
// Stop the shared executor server, wait for all tasks to complete
emLock.lock();
try {
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
// Regenerate the executor service
executorService = new PriorityThreadPoolExecutor();
} catch (final InterruptedException e) {
logSevere(AbstractJpaDAO.class, e);
Thread.currentThread().interrupt();
} finally {
emLock.unlock();
}
}
use of jgnash.engine.concurrent.PriorityThreadPoolExecutor in project jgnash by ccavanaugh.
the class PriorityThreadTest method testPriorityThreadPoolExecutor.
@Test
void testPriorityThreadPoolExecutor() throws Exception {
final AtomicLong atomicLongSequence = new AtomicLong(0);
final PriorityThreadPoolExecutor executorService = new PriorityThreadPoolExecutor();
final List<Future<Void>> futures = new ArrayList<>();
for (int i = 0; i < FUTURES; i++) {
Future<Void> future = executorService.submit(() -> {
final long value = atomicLongSequence.incrementAndGet();
Thread.sleep(DELAY_MILLIS);
System.out.println("Background Callable: " + value);
return null;
}, Priority.BACKGROUND);
futures.add(future);
}
Thread.sleep(1999);
final Future<Void> priorityFuture = executorService.submit(() -> {
final long value = atomicLongSequence.incrementAndGet();
Thread.sleep(DELAY_MILLIS);
System.out.println("System Callable: " + value);
// should not be the last value
assertTrue(value < (FUTURES / 2));
return null;
});
futures.add(priorityFuture);
// wait for futures to complete
for (Future<Void> future : futures) {
future.get();
}
executorService.shutdown();
executorService.shutdownNow();
}
Aggregations