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

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

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

ScheduledThreadPoolExecutor.setRejectedExecutionHandler介绍

暂无

代码示例

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

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

代码示例来源:origin: i2p/i2p.i2p

/**
 * Stops the SimpleTimer.
 * Subsequent executions should not throw a RejectedExecutionException.
 * Cannot be restarted.
 */
public void stop() {
  _executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
  _executor.shutdownNow();
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * Stops the SimpleScheduler.
 * Subsequent executions should not throw a RejectedExecutionException.
 */
public void stop() {
  _executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
  _executor.shutdownNow();
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

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

代码示例来源:origin: org.jboss.threads/jboss-threads

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

代码示例来源:origin: puppetlabs/europa

@Provides @Singleton
protected ScheduledExecutorService getScheduledExecutorService() {
  AtomicInteger threadCounter = new AtomicInteger();
  ThreadFactory threadFactory = (runnable) -> {
    Thread thread = Executors.defaultThreadFactory().newThread(runnable);
    int threadCount = threadCounter.incrementAndGet();
    thread.setName(String.format("ScheduledExecutorService-%d", threadCount));
    return thread;
  };
  ScheduledThreadPoolExecutor threadPool =
    new ScheduledThreadPoolExecutor(10, threadFactory);
  threadPool.setKeepAliveTime(60, TimeUnit.SECONDS);
  threadPool.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
  Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        try {
          threadPool.shutdownNow();
          threadPool.awaitTermination(30, TimeUnit.SECONDS);
        } catch ( Throwable ex ) {
          log.error(ex.getMessage(), ex);
        }
      }
    });
  return threadPool;
}

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

public static ScheduledThreadPoolExecutor createSchedulerThatIgnoresEventsAfterStop(ThreadFactory fact) {
  ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(1, fact);
  s.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
  s.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
  RejectedExecutionHandler handler = new RejectedExecutionHandler() {
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
      if (!executor.isShutdown()) {
        throw new RejectedExecutionException("Rejected Execution: " + r);
      }
      //ignore tasks if shutdown already.
    }
  };
  s.setRejectedExecutionHandler(handler);
  return s;
}

代码示例来源:origin: jetlang/core

public static ScheduledThreadPoolExecutor createSchedulerThatIgnoresEventsAfterStop(ThreadFactory fact) {
  ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(1, fact);
  s.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
  s.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
  RejectedExecutionHandler handler = new RejectedExecutionHandler() {
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
      if (!executor.isShutdown()) {
        throw new RejectedExecutionException("Rejected Execution: " + r);
      }
      //ignore tasks if shutdown already.
    }
  };
  s.setRejectedExecutionHandler(handler);
  return s;
}

代码示例来源:origin: zalando-stups/booties

@Bean(destroyMethod = "shutdown")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public ScheduledExecutorService scheduledExecutorService() {
  ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(properties.getCorePoolSize());
  executor.setMaximumPoolSize(properties.getMaxPoolSize());
  executor.setThreadFactory(new CustomizableThreadFactory(properties.getThreadNamePrefix()));
  executor.setRejectedExecutionHandler(getConfiguredRejectedExecutionHandler());
  return executor;
}

代码示例来源:origin: net.sf.jrtps/jrtps

threadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
threadPoolExecutor.setRemoveOnCancelPolicy(true);
threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());

代码示例来源:origin: org.mobicents.diameter/jdiameter-impl

CommonScheduledExecutorService(String name, Configuration config, final IConcurrentEntityFactory entityFactory, IStatisticManager statisticFactory) {
 super(config == null ? (Integer) Parameters.ConcurrentEntityPoolSize.defValue() : config.getIntValue(Parameters.ConcurrentEntityPoolSize.ordinal(),
   (Integer) Parameters.ConcurrentEntityPoolSize.defValue()));
 this.statisticFactory = statisticFactory;
 this.entityFactory = entityFactory;
 final IStatisticRecord rejectedCount = statisticFactory.newCounterRecord(RejectedTasks);
 execTimeSumm = statisticFactory.newCounterRecord("TimeSumm", "TimeSumm");
 execTimeCount = statisticFactory.newCounterRecord("TimeCount", "TimeCount");
 waitTimeSumm = statisticFactory.newCounterRecord("TimeSumm", "TimeSumm");
 waitTimeCount = statisticFactory.newCounterRecord("TimeCount", "TimeCount");
 //XXX: YYY: no need to remove? it lives as long stack does.
 statistic = statisticFactory.newStatistic(name, ScheduledExecService, rejectedCount);
 final IStatisticRecord execTimeCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.ExecTimeTask, new AbstractTask.AverageValueHolder(
   statistic, IStatisticRecord.Counters.ExecTimeTask), execTimeSumm, execTimeCount);
 final IStatisticRecord waitTimeCounter = statisticFactory.newCounterRecord(IStatisticRecord.Counters.WaitTimeTask, new AbstractTask.AverageValueHolder(
   statistic, IStatisticRecord.Counters.WaitTimeTask), waitTimeSumm, waitTimeCount);
 statistic.appendCounter(statisticFactory.newCounterRecord(WorkingThread), statisticFactory.newCounterRecord(CanceledTasks),
   statisticFactory.newCounterRecord(BrokenTasks), execTimeCounter, waitTimeCounter, statisticFactory.newCounterRecord(WaitTimeTask));
 if (config == null) {
  this.setThreadFactory(entityFactory.newThreadFactory(name));
 } else {
  this.setThreadFactory(entityFactory.newThreadFactory(config.getStringValue(Parameters.ConcurrentEntityDescription.ordinal(), name)));
 }
 super.setRejectedExecutionHandler(entityFactory.newRejectedExecutionHandler(rejectedCount));
}

相关文章

微信公众号

最新文章

更多

ScheduledThreadPoolExecutor类方法