java.util.concurrent.ThreadPoolExecutor.setRejectedExecutionHandler()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中java.util.concurrent.ThreadPoolExecutor.setRejectedExecutionHandler()方法的一些代码示例,展示了ThreadPoolExecutor.setRejectedExecutionHandler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.setRejectedExecutionHandler()方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:setRejectedExecutionHandler

ThreadPoolExecutor.setRejectedExecutionHandler介绍

[英]Sets a new handler for unexecutable tasks.
[中]为不可执行的任务设置新的处理程序。

代码示例

代码示例来源:origin: thinkaurelius/titan

public WorkerPool(int numThreads) {
  processor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(128));
  processor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
}

代码示例来源:origin: JanusGraph/janusgraph

public WorkerPool(int numThreads) {
  processor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(128));
  processor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
}

代码示例来源:origin: wildfly/wildfly

public void setHandoffExecutor(final Executor handoffExecutor) {
  Assert.checkNotNullParam("handoffExecutor", handoffExecutor);
  this.handoffExecutor = handoffExecutor;
  super.setRejectedExecutionHandler(HANDLER);
}

代码示例来源:origin: wildfly/wildfly

public void setRejectedExecutionHandler(final RejectedExecutionHandler handler) {
  super.setRejectedExecutionHandler(new CountingRejectHandler(handler));
}

代码示例来源:origin: apache/activemq

public SimpleCachedLDAPAuthorizationMap() {
  // Allow for only a couple outstanding update request, they can be slow so we
  // don't want a bunch to pile up for no reason.
  updaterService = new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS,
    new LinkedBlockingQueue<Runnable>(2),
    new ThreadFactory() {
      @Override
      public Thread newThread(Runnable r) {
        return new Thread(r, "SimpleCachedLDAPAuthorizationMap update thread");
      }
    });
  updaterService.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

private ReadaheadPool() {
 pool = new ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, 3L, TimeUnit.SECONDS,
   new ArrayBlockingQueue<Runnable>(CAPACITY));
 pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
 pool.setThreadFactory(new ThreadFactoryBuilder()
  .setDaemon(true)
  .setNameFormat("Readahead Thread #%d")
  .build());
}

代码示例来源:origin: Activiti/Activiti

protected void initAsyncJobExecutionThreadPool() {
  if (threadFactory == null) {
   log.warn("A managed thread factory was not found, falling back to self-managed threads");
   super.initAsyncJobExecutionThreadPool();
  } else {
   if (threadPoolQueue == null) {
    log.info("Creating thread pool queue of size {}", queueSize);
    threadPoolQueue = new ArrayBlockingQueue<Runnable>(queueSize);
   }

   if (executorService == null) {
    log.info("Creating executor service with corePoolSize {}, maxPoolSize {} and keepAliveTime {}", corePoolSize, maxPoolSize, keepAliveTime);

    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, threadPoolQueue, threadFactory);
    threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executorService = threadPoolExecutor;

   }

   startJobAcquisitionThread();
  }
 }
}

代码示例来源:origin: qunarcorp/qmq

@PostConstruct
public void init() {
  this.queue = new LinkedBlockingQueue<>(this.queueSize);
  if (this.executor == null) {
    this.executor = new ThreadPoolExecutor(1, threads, 1L, TimeUnit.MINUTES,
        new ArrayBlockingQueue<Runnable>(1), new NamedThreadFactory("batch-" + name + "-task", true));
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
  }
}

代码示例来源:origin: wildfly/wildfly

protected ThreadPoolExecutor createThreadPool() {
  ThreadPoolExecutor threadPool=new ThreadPoolExecutor(0, max_pool, pool_thread_keep_alive,
                             TimeUnit.MILLISECONDS, new SynchronousQueue<>());
  ThreadFactory factory=new ThreadFactory() {
    private final AtomicInteger thread_id=new AtomicInteger(1);
    public Thread newThread(final Runnable command) {
      return getThreadFactory().newThread(command, "StreamingStateTransfer-sender-" + thread_id.getAndIncrement());
    }
  };
  threadPool.setRejectedExecutionHandler(new ShutdownRejectedExecutionHandler(threadPool.getRejectedExecutionHandler()));
  threadPool.setThreadFactory(factory);
  return threadPool;
}

代码示例来源:origin: apache/activemq

protected ExecutorService createDefaultExecutor() {
  ThreadPoolExecutor rc = new ThreadPoolExecutor(getDefaultCorePoolSize(), getMaxThreadPoolSize(), getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
    @Override
    public Thread newThread(Runnable runnable) {
      String threadName = name + "-" + id.incrementAndGet();
      Thread thread = new Thread(runnable, threadName);
      thread.setDaemon(daemon);
      thread.setPriority(priority);
      if (threadClassLoader != null) {
        thread.setContextClassLoader(threadClassLoader);
      }
      thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread t, final Throwable e) {
          LOG.error("Error in thread '{}'", t.getName(), e);
        }
      });
      LOG.trace("Created thread[{}]: {}", threadName, thread);
      return thread;
    }
  });
  if (rejectedTaskHandler != null) {
    rc.setRejectedExecutionHandler(rejectedTaskHandler);
  } else {
    rc.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  }
  return rc;
}

代码示例来源:origin: stackoverflow.com

setRejectedExecutionHandler(defaultHandler);

代码示例来源:origin: apache/hbase

this.longCompactions.setRejectedExecutionHandler(new Rejection());
this.longCompactions.prestartAllCoreThreads();
this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60,
this.shortCompactions.setRejectedExecutionHandler(new Rejection());

代码示例来源:origin: wildfly/wildfly

protected static ExecutorService createThreadPool(int min_threads, int max_threads, long keep_alive_time, String rejection_policy,
                         BlockingQueue<Runnable> queue, final ThreadFactory factory, Log log,
                         boolean use_fork_join_pool, boolean use_common_fork_join_pool) {
  if(use_fork_join_pool) {
    if(use_common_fork_join_pool)
      return ForkJoinPool.commonPool();
    int num_cores=Runtime.getRuntime().availableProcessors();
    if(max_threads > num_cores)
      log.warn("max_threads (%d) is higher than available cores (%d)", max_threads, num_cores);
    return new ForkJoinPool(max_threads, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
  }
  ThreadPoolExecutor pool=new ThreadPoolExecutor(min_threads, max_threads, keep_alive_time, TimeUnit.MILLISECONDS, queue, factory);
  RejectedExecutionHandler handler=Util.parseRejectionPolicy(rejection_policy);
  pool.setRejectedExecutionHandler(new ShutdownRejectedExecutionHandler(handler));
  return pool;
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

highPriorityExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
batchExecutor = new ThreadPoolExecutor(1, nP, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(nP * 2));
batchExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());

代码示例来源:origin: jankotek/mapdb

void setRejectedExecutionHandler(
  ThreadPoolExecutor p, RejectedExecutionHandler handler) {
  p.setRejectedExecutionHandler(handler);
  assertSame(handler, p.getRejectedExecutionHandler());
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory("SEV-" + serverConfig.getProtocol().toUpperCase()
    + "-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory("SEV-" + serverConfig.getProtocol().toUpperCase()
    + "-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory(
    "SEV-BOLT-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: alipay/sofa-rpc

protected ThreadPoolExecutor initThreadPool(ServerConfig serverConfig) {
  ThreadPoolExecutor threadPool = BusinessPool.initPool(serverConfig);
  threadPool.setThreadFactory(new NamedThreadFactory(
    "SEV-BOLT-BIZ-" + serverConfig.getPort(), serverConfig.isDaemon()));
  threadPool.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
  if (serverConfig.isPreStartCore()) { // 初始化核心线程池
    threadPool.prestartAllCoreThreads();
  }
  return threadPool;
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void startExecutingJobs() {
 if (threadPoolExecutor==null || threadPoolExecutor.isShutdown()) {
  BlockingQueue<Runnable> threadPoolQueue = new ArrayBlockingQueue<Runnable>(queueSize);
  threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 0L, TimeUnit.MILLISECONDS, threadPoolQueue);
  threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
 }
 super.startExecutingJobs();
}

相关文章

ThreadPoolExecutor类方法