Java Code Examples for java.util.concurrent.ScheduledThreadPoolExecutor#isTerminated()
The following examples show how to use
java.util.concurrent.ScheduledThreadPoolExecutor#isTerminated() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadPoolTest.java From java-study with Apache License 2.0 | 5 votes |
/** * 创建一个固定长度的线程池,而且以延迟或者定时的方式来执行,类似Timer; */ private static void newScheduledThreadPool() { ScheduledThreadPoolExecutor exec = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(10); //创建大小为10的线程池 for(int i = 0; i < 10; i++) { exec.schedule(new MyThread(String.valueOf(i)), 2, TimeUnit.SECONDS);//延迟2秒执行 } //如果任务都完成了则返回true while(!exec.isTerminated()){ //wait for all tasks to finish // System.out.println("正在运行中..."); } System.out.println("运行结束!"); }
Example 2
Source File: ThreadPoolTest.java From java-study with Apache License 2.0 | 5 votes |
/** * 创建一个固定长度的线程池,而且以延迟或者定时的方式来执行,类似Timer; */ private static void newScheduledThreadPool() { ScheduledThreadPoolExecutor exec = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(10); //创建大小为10的线程池 for(int i = 0; i < 10; i++) { exec.schedule(new MyThread2(String.valueOf(i)), 2, TimeUnit.SECONDS);//延迟2秒执行 } //如果任务都完成了则返回true while(!exec.isTerminated()){ //wait for all tasks to finish // System.out.println("正在运行中..."); } System.out.println("运行结束!"); }
Example 3
Source File: TestShutdownThreadsHelper.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testShutdownThreadPool() throws InterruptedException { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); executor.execute(sampleRunnable); boolean ret = ShutdownThreadsHelper.shutdownExecutorService(executor); boolean isTerminated = executor.isTerminated(); assertEquals("Incorrect return value", ret, isTerminated); assertTrue("ExecutorService is not shutdown", isTerminated); }
Example 4
Source File: TestShutdownThreadsHelper.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testShutdownThreadPool() throws InterruptedException { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); executor.execute(sampleRunnable); boolean ret = ShutdownThreadsHelper.shutdownExecutorService(executor); boolean isTerminated = executor.isTerminated(); assertEquals("Incorrect return value", ret, isTerminated); assertTrue("ExecutorService is not shutdown", isTerminated); }