当前位置: 首页>>代码示例>>Java>>正文


Java ThreadPoolExecutor.shutdown方法代码示例

本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.shutdown方法的具体用法?Java ThreadPoolExecutor.shutdown怎么用?Java ThreadPoolExecutor.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parallelPixelFromGeo

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * 
 * @param coords
 * @return
 * @throws InterruptedException
 * @throws ExecutionException
 */
public List<double[]> parallelPixelFromGeo(final Coordinate[] coords)
		throws InterruptedException, ExecutionException {
	int processors = Runtime.getRuntime().availableProcessors();
	ThreadPoolExecutor executor = new ThreadPoolExecutor(2, processors, 2, TimeUnit.SECONDS,
			new LinkedBlockingQueue<Runnable>());//(ThreadPoolExecutor)Executors.newFixedThreadPool(processors);
	try {
		final List<Future<double[]>> tasks = new ArrayList<Future<double[]>>();
		for (int i = 0; i < coords.length; i++) {
			tasks.add(executor.submit(new ParallelReverse(coords[i].x, coords[i].y)));
		}
		executor.shutdown();

		final List<double[]> points = new ArrayList<double[]>();
		for (Future<double[]> result : tasks) {
			List<double[]> l = Arrays.asList(result.get());
			points.addAll(l);
		}

		return points;
	} catch (Exception e) {
		if (!executor.isShutdown())
			executor.shutdown();
		throw e;
	}
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:33,代码来源:ParallelGeoCoding.java

示例2: parallelGeoFromPixel

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public List<double[]> parallelGeoFromPixel(final Coordinate[] coords)
		throws InterruptedException, ExecutionException {
	int processors = Runtime.getRuntime().availableProcessors();
	ThreadPoolExecutor executor = new ThreadPoolExecutor(2, processors, 5000, TimeUnit.MILLISECONDS,
			new LinkedBlockingQueue<Runnable>());//(ThreadPoolExecutor)Executors.newFixedThreadPool(processors);

	List<Callable<double[]>> tasks = new ArrayList<Callable<double[]>>();
	for (final Coordinate c : coords) {
		tasks.add(new ParallelForward(c.y,c.x));
	}
	List<Future<double[]>> results = executor.invokeAll(tasks);
	executor.shutdown();

	List<double[]> points = new ArrayList<double[]>();
	for (Future<double[]> result : results) {
		List<double[]> l = Arrays.asList(result.get());
		points.addAll(l);
	}

	return points;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:22,代码来源:ParallelGeoCoding.java

示例3: parallelBuffer

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
    *
    * @param bufferedGeom
    * @param bufferDistance
    * @return
    * @throws InterruptedException
    * @throws ExecutionException
    */
   private List<Geometry> parallelBuffer(List<Geometry> bufferedGeom,double bufferDistance)throws InterruptedException, ExecutionException {
	int processors = Runtime.getRuntime().availableProcessors();
	ThreadPoolExecutor executor = new ThreadPoolExecutor(2, processors, 5000, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());

	List<Callable<Geometry>> tasks = new ArrayList<Callable<Geometry>>();
	for (int i=0;i<bufferedGeom.size();i++) {
		 tasks.add(new ParallelBuffer(bufferedGeom.get(i),bufferDistance));
	}
	List<Future<Geometry>> results = executor.invokeAll(tasks);
	executor.shutdown();

	List<Geometry> geoms = new ArrayList<Geometry>();
	for (Future<Geometry> result : results) {
		List<Geometry> l = Arrays.asList(result.get());
		geoms.addAll(l);
	}

	return geoms;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:28,代码来源:MaskVectorLayer.java

示例4: testIsTerminated

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * isTerminated is false before termination, true after
 */
public void testIsTerminated() throws InterruptedException {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 1,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        final CountDownLatch threadStarted = new CountDownLatch(1);
        final CountDownLatch done = new CountDownLatch(1);
        assertFalse(p.isTerminating());
        p.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(p.isTerminating());
                threadStarted.countDown();
                await(done);
            }});
        await(threadStarted);
        assertFalse(p.isTerminating());
        done.countDown();
        try { p.shutdown(); } catch (SecurityException ok) { return; }
        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
        assertTrue(p.isTerminated());
        assertFalse(p.isTerminating());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ThreadPoolExecutorTest.java

示例5: multiThreadUpload

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private ThreadPoolExecutor multiThreadUpload(int threadNum, final int threadFileNum) {

    ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadNum);
    pool.prestartAllCoreThreads();

    for (int i = 0; i < threadNum; ++i) {
      final int threadId = i;
      pool.submit(new Runnable() {
        @Override
        public void run() {
          uploadAndDownloadPerform(threadId, threadFileNum);
        }
      });
    }
    pool.shutdown();
    return pool;
  }
 
开发者ID:XiaoMi,项目名称:ECFileCache,代码行数:18,代码来源:FileCachePerf.java

示例6: testIsTerminated

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * isTerminated is false before termination, true after
 */
public void testIsTerminated() throws InterruptedException {
    final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
    try (PoolCleaner cleaner = cleaner(p)) {
        final CountDownLatch threadStarted = new CountDownLatch(1);
        final CountDownLatch done = new CountDownLatch(1);
        assertFalse(p.isTerminated());
        p.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(p.isTerminated());
                threadStarted.countDown();
                await(done);
            }});
        await(threadStarted);
        assertFalse(p.isTerminating());
        done.countDown();
        try { p.shutdown(); } catch (SecurityException ok) { return; }
        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
        assertTrue(p.isTerminated());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ScheduledExecutorTest.java

示例7: testIsTerminating

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * isTerminating is not true when running or when terminated
 */
public void testIsTerminating() throws InterruptedException {
    final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
    final CountDownLatch threadStarted = new CountDownLatch(1);
    final CountDownLatch done = new CountDownLatch(1);
    try (PoolCleaner cleaner = cleaner(p)) {
        assertFalse(p.isTerminating());
        p.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(p.isTerminating());
                threadStarted.countDown();
                await(done);
            }});
        await(threadStarted);
        assertFalse(p.isTerminating());
        done.countDown();
        try { p.shutdown(); } catch (SecurityException ok) { return; }
        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
        assertTrue(p.isTerminated());
        assertFalse(p.isTerminating());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ScheduledExecutorTest.java

示例8: close

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public static void close(ThreadPoolExecutor executor, Logger logger) {
  executor.shutdown(); // Disable new tasks from being submitted
  try {
    // Wait a while for existing tasks to terminate
    if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
      executor.shutdownNow(); // Cancel currently executing tasks
      // Wait a while for tasks to respond to being cancelled
      if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
        logger.error("Pool did not terminate");
      }
    }
  } catch (InterruptedException ie) {
    logger.warn("Executor interrupted while awaiting termination");

    // (Re-)Cancel if current thread also interrupted
    executor.shutdownNow();
    // Preserve interrupt status
    Thread.currentThread().interrupt();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:AutoCloseables.java

示例9: testIsTerminated

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * isTerminated is false before termination, true after
 */
public void testIsTerminated() throws InterruptedException {
    final CountDownLatch done = new CountDownLatch(1);
    final ThreadPoolExecutor p = new CustomExecutor(1);
    try (PoolCleaner cleaner = cleaner(p)) {
        final CountDownLatch threadStarted = new CountDownLatch(1);
        p.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(p.isTerminated());
                threadStarted.countDown();
                await(done);
            }});
        await(threadStarted);
        assertFalse(p.isTerminated());
        assertFalse(p.isTerminating());
        done.countDown();
        try { p.shutdown(); } catch (SecurityException ok) { return; }
        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
        assertTrue(p.isTerminated());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ScheduledExecutorSubclassTest.java

示例10: realMain

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private static void realMain(String[] args) throws Throwable {
    final int n = 4;
    final CyclicBarrier barrier = new CyclicBarrier(2*n+1);
    final ThreadPoolExecutor pool
        = new ThreadPoolExecutor(n, 2*n,
                                 KEEPALIVE_MS, MILLISECONDS,
                                 new SynchronousQueue<Runnable>());
    final Runnable r = new Runnable() { public void run() {
        try {
            barrier.await();
            barrier.await();
        } catch (Throwable t) { unexpected(t); }}};

    for (int i = 0; i < 2*n; i++)
        pool.execute(r);
    barrier.await();
    checkPoolSizes(pool, 2*n, n, 2*n);
    barrier.await();
    long nap = KEEPALIVE_MS + (KEEPALIVE_MS >> 2);
    for (long sleepyTime = 0L; pool.getPoolSize() > n; ) {
        check((sleepyTime += nap) <= LONG_DELAY_MS);
        Thread.sleep(nap);
    }
    checkPoolSizes(pool, n, n, 2*n);
    Thread.sleep(nap);
    checkPoolSizes(pool, n, n, 2*n);
    pool.shutdown();
    check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:TimeOutShrink.java

示例11: test_Disconnect_Execute_Error

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Test(expected = ExecutionException.class)
public void test_Disconnect_Execute_Error() throws RemotingException{
    handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
    ThreadPoolExecutor executor = (ThreadPoolExecutor)getField(handler, "connectionExecutor", 1);
    executor.shutdown();
    handler.disconnected(new MockedChannel());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:ConnectChannelHandlerTest.java

示例12: mark

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Marks all of the submissions.
 * @param threads The thread-pool size to use in marking the assignments
 */
public void mark(final int threads)
    throws Exception {
    final ProgressBar pb = new ProgressBar("Marking", this.submissions.size());
    pb.start();
    final CountDownLatch latch = new CountDownLatch(this.submissions.size());
    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
        threads,
        threads,
        0L,
        TimeUnit.MILLISECONDS,
        new ArrayBlockingQueue<>(threads),
        new ThreadPoolExecutor.CallerRunsPolicy()
    );
    for (Submission s : this.submissions) {
        executor.submit(() -> {
            try {
                s.results(this.markingResults(s.directory()));
                pb.step();
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                latch.countDown();
            }
        });
    }
    executor.shutdown();
    latch.await();
    pb.stop();
}
 
开发者ID:jachinte,项目名称:grade-buddy,代码行数:34,代码来源:AutomatedMarking.java

示例13: test

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
void test(String[] args) throws Throwable {
    final int n = 100;
    final ThreadPoolExecutor pool =
        new ThreadPoolExecutor(n, n, 1L, TimeUnit.NANOSECONDS,
                               new SynchronousQueue<Runnable>());
    final CountDownLatch startingGate = new CountDownLatch(n);
    final CountDownLatch finishLine = new CountDownLatch(n);
    equal(pool.getCorePoolSize(), n);
    equal(pool.getPoolSize(), 0);
    for (int i = 0; i < n; i++)
        pool.execute(new Runnable() { public void run() {
            try {
                startingGate.countDown();
                startingGate.await();
                equal(pool.getPoolSize(), n);
                pool.setCorePoolSize(n);
                pool.setCorePoolSize(1);
                check(! Thread.interrupted());
                equal(pool.getPoolSize(), n);
                finishLine.countDown();
                finishLine.await();
                check(! Thread.interrupted());
            } catch (Throwable t) { unexpected(t); }}});
    finishLine.await();
    pool.shutdown();
    check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:SelfInterrupt.java

示例14: testDiscardOldestOnShutdown

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * execute using DiscardOldestPolicy drops task on shutdown
 */
public void testDiscardOldestOnShutdown() {
    final ThreadPoolExecutor p =
        new CustomTPE(1, 1,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(1),
                      new ThreadPoolExecutor.DiscardOldestPolicy());

    try { p.shutdown(); } catch (SecurityException ok) { return; }
    try (PoolCleaner cleaner = cleaner(p)) {
        TrackedNoOpRunnable r = new TrackedNoOpRunnable();
        p.execute(r);
        assertFalse(r.done);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ThreadPoolExecutorSubclassTest.java

示例15: removeVolume

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Stops AsyncLazyPersistService for a volume.
 * @param volume the root of the volume.
 */
synchronized void removeVolume(File volume) {
  if (executors == null) {
    throw new RuntimeException("AsyncDiskService is already shutdown");
  }
  ThreadPoolExecutor executor = executors.get(volume);
  if (executor == null) {
    throw new RuntimeException("Can not find volume " + volume
      + " to remove.");
  } else {
    executor.shutdown();
    executors.remove(volume);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:RamDiskAsyncLazyPersistService.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。