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 File: QuartzThreadPool.java    From nexus-public with 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 File: Web3Config.java    From WeBASE-Front with 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 File: Web3Config.java    From WeBASE-Transaction with 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 File: ThreadConfig.java    From WeBASE-Transaction with 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 File: d.java    From letv with 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 File: AbstractDependencyManager.java    From status with 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 File: SaturationPolicyUnitTest.java    From tutorials with 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 File: ThreadPoolExecutorBuilder.java    From riptide with MIT License 4 votes vote down vote up
public ThreadPoolExecutorBuilder() {
    this(null, null, null, null, false, null,
            defaultThreadFactory(), new AbortPolicy());
}