use of java.util.concurrent.ThreadPoolExecutor in project WordPress-Android by wordpress-mobile.
the class StatsFollowersFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Single background thread used to create the blogs list in BG
ThreadPoolExecutor blogsListCreatorExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
blogsListCreatorExecutor.submit(new Thread() {
@Override
public void run() {
// Read all the .com and jetpack sites and get the list of home URLs.
// This will be used later to check if the user is a member of followers blog marked as private.
List<SiteModel> sites = mSiteStore.getWPComAndJetpackSites();
for (SiteModel site : sites) {
if (site.getUrl() != null && site.getSiteId() != 0) {
String normURL = normalizeAndRemoveScheme(site.getUrl());
long blogID = site.getSiteId();
userBlogs.put(normURL, blogID);
}
}
}
});
}
use of java.util.concurrent.ThreadPoolExecutor in project hazelcast by hazelcast.
the class DelegateAndSkipOnConcurrentExecutionDecoratorTest method givenTheTaskIsNotRunning_whenThreadAttemptToExecuteIt_theTaskWillBeExecuted.
@Test
public void givenTheTaskIsNotRunning_whenThreadAttemptToExecuteIt_theTaskWillBeExecuted() throws InterruptedException {
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
ResumableCountingRunnable task = new ResumableCountingRunnable();
decorateAndInvokeRunOnDifferentThread(task, executor);
task.awaitExecutionStarted();
task.resumeExecution();
assertEquals(1, task.getExecutionCount());
}
use of java.util.concurrent.ThreadPoolExecutor in project hazelcast by hazelcast.
the class DelegateAndSkipOnConcurrentExecutionDecoratorTest method givenTheTaskIsAlreadyRunning_whenThreadAttemptToExecuteIt_theExutionWillBeSkipped.
@Test
public void givenTheTaskIsAlreadyRunning_whenThreadAttemptToExecuteIt_theExutionWillBeSkipped() throws InterruptedException {
final ResumableCountingRunnable task = new ResumableCountingRunnable();
final AtomicInteger counter = new AtomicInteger();
SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>() {
@Override
public boolean offer(Runnable runnable) {
counter.incrementAndGet();
return super.offer(runnable);
}
};
ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, queue);
//start first task
DelegateAndSkipOnConcurrentExecutionDecorator decoratedTask = decorateAndInvokeRunOnDifferentThread(task, executor);
//wait until the task is running
task.awaitExecutionStarted();
//attempt to start execution from the test thread. this execution should be skipped -> it won't block
decoratedTask.run();
//resume the original task
task.resumeExecution();
assertEquals(1, task.getExecutionCount());
assertEquals(1, counter.get());
}
use of java.util.concurrent.ThreadPoolExecutor in project spring-framework by spring-projects.
the class ThreadPoolExecutorFactoryBean method initializeExecutor.
@Override
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
ThreadPoolExecutor executor = createExecutor(this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
if (this.allowCoreThreadTimeOut) {
executor.allowCoreThreadTimeOut(true);
}
// Wrap executor with an unconfigurable decorator.
this.exposedExecutor = (this.exposeUnconfigurableExecutor ? Executors.unconfigurableExecutorService(executor) : executor);
return executor;
}
use of java.util.concurrent.ThreadPoolExecutor in project spring-framework by spring-projects.
the class ThreadPoolTaskExecutor method initializeExecutor.
/**
* Note: This method exposes an {@link ExecutorService} to its base class
* but stores the actual {@link ThreadPoolExecutor} handle internally.
* Do not override this method for replacing the executor, rather just for
* decorating its {@code ExecutorService} handle or storing custom state.
*/
@Override
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
ThreadPoolExecutor executor;
if (this.taskDecorator != null) {
executor = new ThreadPoolExecutor(this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS, queue, threadFactory, rejectedExecutionHandler) {
@Override
public void execute(Runnable command) {
super.execute(taskDecorator.decorate(command));
}
};
} else {
executor = new ThreadPoolExecutor(this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS, queue, threadFactory, rejectedExecutionHandler);
}
if (this.allowCoreThreadTimeOut) {
executor.allowCoreThreadTimeOut(true);
}
this.threadPoolExecutor = executor;
return executor;
}
Aggregations