类java.util.concurrent.ThreadPoolExecutor.AbortPolicy源码实例Demo

下面列出了怎么用java.util.concurrent.ThreadPoolExecutor.AbortPolicy的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: nexus-public   文件: QuartzThreadPool.java
public QuartzThreadPool(final int poolSize, final int threadPriority) {
  checkArgument(poolSize > 0, "Pool size must be greater than zero");
  checkArgument(threadPriority >= Thread.MIN_PRIORITY && threadPriority <= Thread.MAX_PRIORITY, String
      .format("Thread priority value must be an int between %s and %s", Thread.MIN_PRIORITY, Thread.MAX_PRIORITY));

  this.threadPoolExecutor = new ThreadPoolExecutor(
      poolSize, // core-size
      poolSize, // max-size
      0L, // keep-alive
      TimeUnit.MILLISECONDS,
      new SynchronousQueue<>(), // no queuing
      new NexusThreadFactory("quartz", "nx-tasks", threadPriority),
      new AbortPolicy());

  // wrapper for Shiro integration
  this.nexusExecutorService = NexusExecutorService.forFixedSubject(
      threadPoolExecutor, FakeAlmightySubject.TASK_SUBJECT);

  semaphore = new Semaphore(poolSize);
}
 
源代码2 项目: WeBASE-Front   文件: Web3Config.java
/**
 * set sdk threadPool.
 *
 * @return
 */
@Bean
public ThreadPoolTaskExecutor sdkThreadPool() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setKeepAliveSeconds(keepAlive);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("sdkThreadPool-");
    executor.initialize();
    return executor;
}
 
源代码3 项目: WeBASE-Transaction   文件: Web3Config.java
/**
 * set sdk threadPool.
 * 
 * @return
 */
@Bean
public ThreadPoolTaskExecutor sdkThreadPool() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setKeepAliveSeconds(keepAlive);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("sdkThreadPool-");
    executor.initialize();
    return executor;
}
 
源代码4 项目: WeBASE-Transaction   文件: ThreadConfig.java
/**
 * set ThreadPoolTaskExecutor.
 * 
 * @return
 */
@Bean
public ThreadPoolTaskExecutor transExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(50);
    executor.setMaxPoolSize(100);
    executor.setQueueCapacity(500);
    executor.setKeepAliveSeconds(60);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("transExecutor-");
    executor.initialize();
    return executor;
}
 
源代码5 项目: letv   文件: d.java
public final synchronized void a(Runnable runnable) {
    if (runnable != null) {
        try {
            if (this.a == null || this.a.isShutdown()) {
                this.a = new ThreadPoolExecutor(this.b, this.c, this.d, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), Executors.defaultThreadFactory(), new AbortPolicy());
            }
            this.a.execute(runnable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
源代码6 项目: status   文件: AbstractDependencyManager.java
static ThreadPoolExecutor newDefaultThreadPool() {
    final ThreadPoolExecutor result = new ThreadPoolExecutor(
            // Bound the pool. Most foreground dependency managers should be called only very rarely, so
            //  keep a minimal core pool around and only grow it on demand.
            1, 16,
            // Threads will be kept alive in an idle state for a minute or two. After that, they may be
            //  garbage-collected, so that we're keeping a larger thread pool only during weird periods of
            //  congestion. (Note: the background manager will typically keep all threads pretty active, since it's
            //  repeatedly launching new pingers. The live manager will spin them up and down based on traffic to
            //  the rather uncommonly used /healthcheck/live uri).
            30, TimeUnit.SECONDS,
            // Use a blocking queue just to keep track of checks when the world is going wrong. This is mostly useful
            //  when we're adding a bunch of checks at the same time, such as during a live healthcheck. Might as well
            //  keep this pretty small, because any nontrivial wait to execute is going to blow up a timeout anyway.
            new SynchronousQueue<Runnable>(),
            // Name your threads.
            new ThreadFactoryBuilder()
                    .setNameFormat("dependency-default-" + DEFAULT_THREAD_POOL_COUNT.getAndIncrement() + "-checker-%d")
                    .setDaemon(true)
                    .setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                        @Override
                        public void uncaughtException(Thread t, Throwable e) {
                            Logger.getLogger(AbstractDependencyManager.class)
                                    .error("Uncaught throwable in thread " + t.getName() + "/" + t.getId(), e);
                        }
                    })
                    .build(),
            // Explicitly restating the default policy here, because healthchecks should Just Not Work if there
            //  are insufficient resources to support them. Given the smallish queue above, this means that
            //  we're going to end up throwing exceptions if we get too blocked up somehow.
            new AbortPolicy());

    result.prestartAllCoreThreads();

    return result;
}
 
源代码7 项目: tutorials   文件: SaturationPolicyUnitTest.java
@Ignore
@Test
public void givenAbortPolicy_WhenSaturated_ThenShouldThrowRejectedExecutionException() {
    executor = new ThreadPoolExecutor(1, 1, 0, MILLISECONDS, new SynchronousQueue<>(), new AbortPolicy());
    executor.execute(() -> waitFor(250));

    assertThatThrownBy(() -> executor.execute(() -> System.out.println("Will be rejected"))).isInstanceOf(RejectedExecutionException.class);
}
 
源代码8 项目: riptide   文件: ThreadPoolExecutorBuilder.java
public ThreadPoolExecutorBuilder() {
    this(null, null, null, null, false, null,
            defaultThreadFactory(), new AbortPolicy());
}
 
 类所在包
 同包方法