use of java.util.concurrent.ThreadPoolExecutor in project bazel by bazelbuild.
the class AbstractQueueVisitorTest method interruptionWithInterruptingWorkers.
@Test
public void interruptionWithInterruptingWorkers() throws Exception {
assertInterruptWorkers(null);
ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 3, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
assertInterruptWorkers(executor);
executor.shutdown();
executor.awaitTermination(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class SpringCamelContextThreadPoolProfilesTest method testBigProfile.
public void testBigProfile() throws Exception {
CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("big");
assertEquals(50, profile.getPoolSize().intValue());
assertEquals(100, profile.getMaxPoolSize().intValue());
assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, profile.getRejectedPolicy());
assertEquals(null, profile.getKeepAliveTime());
assertEquals(null, profile.getMaxQueueSize());
// create a thread pool from big
ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyBig", "big");
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
assertEquals(50, tp.getCorePoolSize());
assertEquals(100, tp.getMaximumPoolSize());
// should inherit default options
assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("DiscardOldest", tp.getRejectedExecutionHandler().toString());
}
use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.
the class SpringCamelContextThreadPoolProfilesTest method testLowProfile.
public void testLowProfile() throws Exception {
CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("low");
assertEquals(1, profile.getPoolSize().intValue());
assertEquals(5, profile.getMaxPoolSize().intValue());
assertEquals(null, profile.getKeepAliveTime());
assertEquals(null, profile.getMaxQueueSize());
assertEquals(null, profile.getRejectedPolicy());
// create a thread pool from low
ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyLow", "low");
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
assertEquals(1, tp.getCorePoolSize());
assertEquals(5, tp.getMaximumPoolSize());
// should inherit default options
assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("CallerRuns", tp.getRejectedExecutionHandler().toString());
}
use of java.util.concurrent.ThreadPoolExecutor in project jedis by xetorthio.
the class JedisClusterTest method testJedisClusterRunsWithMultithreaded.
@Test
public void testJedisClusterRunsWithMultithreaded() throws InterruptedException, ExecutionException, IOException {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
final JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
jc.set("foo", "bar");
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
List<Future<String>> futures = new ArrayList<Future<String>>();
for (int i = 0; i < 50; i++) {
executor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
// random connection also does work
return jc.get("foo");
}
});
}
for (Future<String> future : futures) {
String value = future.get();
assertEquals("bar", value);
}
jc.close();
}
use of java.util.concurrent.ThreadPoolExecutor in project android-priority-jobqueue by yigit.
the class MultiThreadTest method testMultiThreaded.
@Test
public void testMultiThreaded() throws Exception {
multiThreadedJobCounter = new AtomicInteger(0);
final JobManager jobManager = createJobManager(new Configuration.Builder(RuntimeEnvironment.application).loadFactor(3).maxConsumerCount(10));
int limit = 200;
ExecutorService executor = new ThreadPoolExecutor(20, 20, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(limit));
final String cancelTag = "iWillBeCancelled";
Collection<Future<?>> futures = new LinkedList<Future<?>>();
for (int i = 0; i < limit; i++) {
final int id = i;
futures.add(executor.submit(new Runnable() {
@Override
public void run() {
final boolean persistent = Math.round(Math.random()) % 2 == 0;
boolean requiresNetwork = Math.round(Math.random()) % 2 == 0;
int priority = (int) (Math.round(Math.random()) % 10);
multiThreadedJobCounter.incrementAndGet();
Params params = new Params(priority).setRequiresNetwork(requiresNetwork).setPersistent(persistent);
if (Math.random() < .1) {
params.addTags(cancelTag);
}
jobManager.addJob(new DummyJobForMultiThread(id, params));
}
}));
}
// wait for some jobs to start
//noinspection SLEEP_IN_CODE
Thread.sleep(1000);
CancelResult cancelResult = jobManager.cancelJobs(TagConstraint.ALL, cancelTag);
for (int i = 0; i < cancelResult.getCancelledJobs().size(); i++) {
multiThreadedJobCounter.decrementAndGet();
}
for (Future<?> future : futures) {
future.get();
}
Log.d("TAG", "added all jobs");
//wait until all jobs are added
//noinspection DIRECT_TIME_ACCESS
long start = System.nanoTime();
//20 minutes
long timeLimit = JobManager.NS_PER_MS * 60000 * 20;
//noinspection DIRECT_TIME_ACCESS
while (System.nanoTime() - start < timeLimit && multiThreadedJobCounter.get() != 0) {
//noinspection SLEEP_IN_CODE
Thread.sleep(1000);
}
MatcherAssert.assertThat("jobmanager count should be 0", jobManager.count(), equalTo(0));
jobManager.stopAndWaitUntilConsumersAreFinished();
MatcherAssert.assertThat("multiThreadedJobCounter should be 0", multiThreadedJobCounter.get(), CoreMatchers.is(0));
}
Aggregations