java.util.concurrent.ThreadPoolExecutor.AbortPolicy Java Examples

The following examples show how to use java.util.concurrent.ThreadPoolExecutor.AbortPolicy. 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 Project: nexus-public   Author: sonatype   File: QuartzThreadPool.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #2
Source Project: WeBASE-Front   Author: WeBankFinTech   File: Web3Config.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source Project: WeBASE-Transaction   Author: WeBankFinTech   File: Web3Config.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source Project: WeBASE-Transaction   Author: WeBankFinTech   File: ThreadConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source Project: letv   Author: JackChan1999   File: d.java    License: Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example #6
Source Project: status   Author: indeedeng   File: AbstractDependencyManager.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source Project: tutorials   Author: eugenp   File: SaturationPolicyUnitTest.java    License: MIT License 5 votes vote down vote up
@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);
}
 
Example #8
Source Project: riptide   Author: zalando   File: ThreadPoolExecutorBuilder.java    License: MIT License 4 votes vote down vote up
public ThreadPoolExecutorBuilder() {
    this(null, null, null, null, false, null,
            defaultThreadFactory(), new AbortPolicy());
}