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

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

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

ThreadPoolExecutor.getRejectedExecutionHandler介绍

[英]Returns the current handler for unexecutable tasks.
[中]返回不可执行任务的当前处理程序。

代码示例

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

/** {@inheritDoc} */
@Override public String getRejectedExecutionHandlerClass() {
  if (!(exec instanceof ThreadPoolExecutor))
    return "";
  RejectedExecutionHandler hnd = ((ThreadPoolExecutor)exec).getRejectedExecutionHandler();
  return hnd == null ? "" : hnd.getClass().getName();
}

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

public JBossThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
  super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
  setRejectedExecutionHandler(super.getRejectedExecutionHandler());
}

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

public JBossThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
  super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
  setRejectedExecutionHandler(super.getRejectedExecutionHandler());
}

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

public RejectedExecutionHandler getRejectedExecutionHandler() {
  return ((CountingRejectHandler)super.getRejectedExecutionHandler()).getDelegate();
}

代码示例来源: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: jankotek/mapdb

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

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

void assertTaskSubmissionsAreRejected(ThreadPoolExecutor p) {
  final RejectedExecutionHandler savedHandler = p.getRejectedExecutionHandler();
  final long savedTaskCount = p.getTaskCount();
  final long savedCompletedTaskCount = p.getCompletedTaskCount();

代码示例来源:origin: org.elasticsearch/elasticsearch

public ThreadPoolStats stats() {
  List<ThreadPoolStats.Stats> stats = new ArrayList<>();
  for (ExecutorHolder holder : executors.values()) {
    final String name = holder.info.getName();
    // no need to have info on "same" thread pool
    if ("same".equals(name)) {
      continue;
    }
    int threads = -1;
    int queue = -1;
    int active = -1;
    long rejected = -1;
    int largest = -1;
    long completed = -1;
    if (holder.executor() instanceof ThreadPoolExecutor) {
      ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) holder.executor();
      threads = threadPoolExecutor.getPoolSize();
      queue = threadPoolExecutor.getQueue().size();
      active = threadPoolExecutor.getActiveCount();
      largest = threadPoolExecutor.getLargestPoolSize();
      completed = threadPoolExecutor.getCompletedTaskCount();
      RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler();
      if (rejectedExecutionHandler instanceof XRejectedExecutionHandler) {
        rejected = ((XRejectedExecutionHandler) rejectedExecutionHandler).rejected();
      }
    }
    stats.add(new ThreadPoolStats.Stats(name, threads, queue, active, rejected, largest, completed));
  }
  return new ThreadPoolStats(stats);
}

代码示例来源:origin: org.apache.ignite/ignite-core

/** {@inheritDoc} */
@Override public String getRejectedExecutionHandlerClass() {
  if (!(exec instanceof ThreadPoolExecutor))
    return "";
  RejectedExecutionHandler hnd = ((ThreadPoolExecutor)exec).getRejectedExecutionHandler();
  return hnd == null ? "" : hnd.getClass().getName();
}

代码示例来源:origin: org.gridgain/gridgain-core

/** {@inheritDoc} */
@Override public String getRejectedExecutionHandlerClass() {
  assert exec != null;
  if (!(exec instanceof ThreadPoolExecutor))
    return "";
  RejectedExecutionHandler hnd = ((ThreadPoolExecutor)exec).getRejectedExecutionHandler();
  return hnd == null ? "" : hnd.getClass().getName();
}

代码示例来源:origin: io.joshworks/snappy

private static void logExecutors(String name, ThreadPoolExecutor executor) {
  System.err.println(String.format("Pool name: %s", name));
  System.err.println(String.format("   Core pool size: %d", executor.getCorePoolSize()));
  System.err.println(String.format("   Maximum pool size: %d", executor.getMaximumPoolSize()));
  System.err.println(String.format("   Queue size: %d", executor.getQueue().remainingCapacity()));
  System.err.println(String.format("   Rejection policy: %s", executor.getRejectedExecutionHandler().getClass().getSimpleName()));
}

代码示例来源:origin: io.joshworks/snappy-core

private static void logExecutors(String name, ThreadPoolExecutor executor) {
  System.err.println(String.format("Pool name: %s", name));
  System.err.println(String.format("   Core pool size: %d", executor.getCorePoolSize()));
  System.err.println(String.format("   Maximum pool size: %d", executor.getMaximumPoolSize()));
  System.err.println(String.format("   Queue size: %d", executor.getQueue().remainingCapacity()));
  System.err.println(String.format("   Rejection policy: %s", executor.getRejectedExecutionHandler().getClass().getSimpleName()));
}

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

@Managed
public String getRejectedExecutionHandler()
{
  return threadPoolExecutor.getRejectedExecutionHandler().getClass().getName();
}

代码示例来源:origin: com.teradata.airlift/concurrent

@Managed
public String getRejectedExecutionHandler()
{
  return threadPoolExecutor.getRejectedExecutionHandler().getClass().getName();
}

代码示例来源:origin: co.paralleluniverse/galaxy

@Override
public String getRejectedExecutionHandler() {
  final ThreadPoolExecutor executor = getMonitored();
  if (executor == null)
    return null;
  return executor.getRejectedExecutionHandler().toString();
}

代码示例来源:origin: com.proofpoint.platform/concurrent

@Managed
public String getRejectedExecutionHandler()
{
  return threadPoolExecutor.getRejectedExecutionHandler().getClass().getName();
}

代码示例来源:origin: org.opendaylight.controller/sal-common-util

@Override
public Long getRejectedTaskCount() {
  RejectedExecutionHandler rejectedHandler = executor.getRejectedExecutionHandler();
  if(rejectedHandler instanceof CountingRejectedExecutionHandler) {
    return Long.valueOf(((CountingRejectedExecutionHandler)rejectedHandler)
                                 .getRejectedTaskCount());
  }
  return null;
}

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

protected ThreadPoolExecutor createThreadPool() {
  ThreadPoolExecutor threadPool=new ThreadPoolExecutor(0, max_pool, pool_thread_keep_alive,
                             TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
  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: org.apache.tez/tez-common

private void addFuture(ManagedFutureTask<?> future) {
 futures.put(future, Boolean.TRUE);
 // If already shutdown, reject this task.
 if (isShutdown()) {
  service.getRejectedExecutionHandler().rejectedExecution(future, service);
 }
}

代码示例来源:origin: apache/maven-surefire

/**
 * @see Scheduler.ShutdownHandler
 */
@Override
protected void setDefaultShutdownHandler( Scheduler.ShutdownHandler handler )
{
  if ( threadPool instanceof ThreadPoolExecutor )
  {
    ThreadPoolExecutor pool = (ThreadPoolExecutor) threadPool;
    handler.setRejectedExecutionHandler( pool.getRejectedExecutionHandler() );
    pool.setRejectedExecutionHandler( handler );
  }
}

相关文章

ThreadPoolExecutor类方法