use of java.util.concurrent.ExecutorService in project hibernate-orm by hibernate.
the class ConcurrentWriteTest method testManyUsers.
// Ignoring the test as it's more of a stress-test: this should be enabled manually
@Ignore
@Test
public void testManyUsers() throws Throwable {
try {
// setup - create users
for (int i = 0; i < USER_COUNT; i++) {
Customer customer = createCustomer(0);
getCustomerIDs().add(customer.getId());
}
assertEquals("failed to create enough Customers", USER_COUNT, getCustomerIDs().size());
final ExecutorService executor = Executors.newFixedThreadPool(USER_COUNT);
CyclicBarrier barrier = new CyclicBarrier(USER_COUNT + 1);
List<Future<Void>> futures = new ArrayList<Future<Void>>(USER_COUNT);
for (Integer customerId : getCustomerIDs()) {
Future<Void> future = executor.submit(new UserRunner(customerId, barrier));
futures.add(future);
// rampup
Thread.sleep(LAUNCH_INTERVAL_MILLIS);
}
// wait for all threads to finish
barrier.await(2, TimeUnit.MINUTES);
log.info("All threads finished, let's shutdown the executor and check whether any exceptions were reported");
for (Future<Void> future : futures) {
future.get();
}
executor.shutdown();
log.info("All future gets checked");
} catch (Throwable t) {
log.error("Error running test", t);
throw t;
}
}
use of java.util.concurrent.ExecutorService in project languagetool by languagetool-org.
the class MultiThreadedJLanguageTool method performCheck.
@Override
protected List<RuleMatch> performCheck(List<AnalyzedSentence> analyzedSentences, List<String> sentences, List<Rule> allRules, ParagraphHandling paraMode, AnnotatedText annotatedText, RuleMatchListener listener) throws IOException {
int charCount = 0;
int lineCount = 0;
int columnCount = 1;
List<RuleMatch> ruleMatches = new ArrayList<>();
ExecutorService executorService = getExecutorService();
try {
List<Callable<List<RuleMatch>>> callables = createTextCheckCallables(paraMode, annotatedText, analyzedSentences, sentences, allRules, charCount, lineCount, columnCount, listener);
List<Future<List<RuleMatch>>> futures = executorService.invokeAll(callables);
for (Future<List<RuleMatch>> future : futures) {
ruleMatches.addAll(future.get());
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
return ruleMatches;
}
use of java.util.concurrent.ExecutorService in project jersey by jersey.
the class TransportFilter method initializeChannelGroup.
private void initializeChannelGroup() throws IOException {
if (closeWaitTask != null) {
closeWaitTask.cancel(true);
closeWaitTask = null;
}
if (channelGroup == null) {
ThreadFactory threadFactory = threadPoolConfig.getThreadFactory();
if (threadFactory == null) {
threadFactory = new TransportThreadFactory(threadPoolConfig);
}
ExecutorService executor;
if (threadPoolConfig.getQueue() != null) {
executor = new QueuingExecutor(threadPoolConfig.getCorePoolSize(), threadPoolConfig.getMaxPoolSize(), threadPoolConfig.getKeepAliveTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, threadPoolConfig.getQueue(), false, threadFactory);
} else {
int taskQueueLimit = threadPoolConfig.getQueueLimit();
if (taskQueueLimit == -1) {
taskQueueLimit = Integer.MAX_VALUE;
}
executor = new QueuingExecutor(threadPoolConfig.getCorePoolSize(), threadPoolConfig.getMaxPoolSize(), threadPoolConfig.getKeepAliveTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(taskQueueLimit), true, threadFactory);
}
// Thread pool is owned by the channel group and will be shut down when channel group is shut down
channelGroup = AsynchronousChannelGroup.withCachedThreadPool(executor, threadPoolConfig.getCorePoolSize());
}
}
use of java.util.concurrent.ExecutorService in project mapdb by jankotek.
the class Collection8Test method testForEachConcurrentStressTest.
public void testForEachConcurrentStressTest() throws Throwable {
if (!impl.isConcurrent())
return;
final Collection c = impl.emptyCollection();
final long testDurationMillis = SHORT_DELAY_MS;
final AtomicBoolean done = new AtomicBoolean(false);
final Object elt = impl.makeElement(1);
ExecutorService pool = Executors.newCachedThreadPool();
Runnable checkElt = () -> {
while (!done.get()) c.stream().forEach((x) -> {
assertSame(x, elt);
});
};
Runnable addRemove = () -> {
while (!done.get()) {
assertTrue(c.add(elt));
assertTrue(c.remove(elt));
}
};
Future<?> f1 = pool.submit(checkElt);
Future<?> f2 = pool.submit(addRemove);
Thread.sleep(testDurationMillis);
done.set(true);
pool.shutdown();
assertTrue(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
assertNull(f1.get(LONG_DELAY_MS, MILLISECONDS));
assertNull(f2.get(LONG_DELAY_MS, MILLISECONDS));
}
use of java.util.concurrent.ExecutorService in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPollInExecutor.
/**
* timed poll retrieves elements across Executor threads
*/
public void testPollInExecutor() {
final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
final CheckedBarrier threadsStarted = new CheckedBarrier(2);
final ExecutorService executor = Executors.newFixedThreadPool(2);
try (PoolCleaner cleaner = cleaner(executor)) {
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertNull(q.poll());
threadsStarted.await();
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
checkEmpty(q);
}
});
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadsStarted.await();
q.put(one);
}
});
}
}
Aggregations