本文整理汇总了Java中java.util.concurrent.ScheduledThreadPoolExecutor.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java ScheduledThreadPoolExecutor.shutdown方法的具体用法?Java ScheduledThreadPoolExecutor.shutdown怎么用?Java ScheduledThreadPoolExecutor.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ScheduledThreadPoolExecutor
的用法示例。
在下文中一共展示了ScheduledThreadPoolExecutor.shutdown方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void test(String[] args) throws Throwable {
ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(0);
Runnable task = new Runnable() {
public void run() {
taskRun = true;
}
};
check(pool.getCorePoolSize() == 0);
pool.schedule(task, 1, TimeUnit.SECONDS);
pool.shutdown();
check(pool.awaitTermination(20L, TimeUnit.SECONDS));
check(pool.getCorePoolSize() == 0);
check(taskRun);
}
示例2: test
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void test(String[] args) throws Throwable {
ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(0);
Runnable task = new Runnable() {
public void run() {
taskRun = true;
}
};
check(pool.getCorePoolSize() == 0);
pool.schedule(task, 12L, MILLISECONDS);
pool.shutdown();
check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
check(pool.getCorePoolSize() == 0);
check(taskRun);
}
示例3: test
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void test(String[] args) throws Throwable {
final ScheduledThreadPoolExecutor pool =
new ScheduledThreadPoolExecutor(1);
// Needed to avoid OOME
pool.setRemoveOnCancelPolicy(true);
final long moreThanYouCanChew = Runtime.getRuntime().freeMemory() / 4;
System.out.printf("moreThanYouCanChew=%d%n", moreThanYouCanChew);
Runnable noopTask = new Runnable() { public void run() {}};
for (long i = 0; i < moreThanYouCanChew; i++)
pool.schedule(noopTask, 10, TimeUnit.MINUTES).cancel(true);
pool.shutdown();
check(pool.awaitTermination(1L, TimeUnit.DAYS));
checkTerminated(pool);
equal(pool.getTaskCount(), 0L);
equal(pool.getCompletedTaskCount(), 0L);
}
示例4: testIsShutdown
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
* isShutdown is false before shutdown, true after
*/
public void testIsShutdown() {
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
assertFalse(p.isShutdown());
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.shutdown();
assertTrue(p.isShutdown());
} catch (SecurityException ok) {}
}
}
示例5: cleanUp
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public static void cleanUp() {
for (ScheduledThreadPoolExecutor executor : ALLEXECUTORS) {
executor.shutdown();
}
ALLEXECUTORS.clear();
numberOfCloseMethodCalls = 0;
}
示例6: main
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
final CountDownLatch count = new CountDownLatch(1000);
final ScheduledThreadPoolExecutor pool =
new ScheduledThreadPoolExecutor(100);
pool.prestartAllCoreThreads();
final Runnable incTask = new Runnable() { public void run() {
count.countDown();
}};
pool.scheduleAtFixedRate(incTask, 0, 10, TimeUnit.MILLISECONDS);
count.await();
pool.shutdown();
pool.awaitTermination(1L, TimeUnit.DAYS);
}