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

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

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

ScheduledThreadPoolExecutor.isShutdown介绍

暂无

代码示例

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

/**
 * @return true when the service is shutdown and thus cannot be used anymore
 */
public boolean isShutdown() {
 return scheduler.isShutdown();
}

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

@Override
public boolean isShutdown() {
 return timer.isShutdown();
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public void run() {
    for (ScheduledThreadPoolExecutor e : new ArrayList<ScheduledThreadPoolExecutor>(POOLS.keySet())) {
      if (e.isShutdown()) {
        POOLS.remove(e);
      } else {
        e.purge();
      }
    }
  }
}

代码示例来源:origin: ehcache/ehcache3

public boolean isShutdown() {
 return scheduler.isShutdown();
}

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

@Override
  public void run() {
    for (ScheduledThreadPoolExecutor e : new ArrayList<ScheduledThreadPoolExecutor>(POOLS.keySet())) {
      if (e.isShutdown()) {
        POOLS.remove(e);
      } else {
        e.purge();
      }
    }
  }
}

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

/**
 * Sets the policy on whether to execute existing delayed
 * tasks even when this executor has been {@code shutdown}.
 * In this case, these tasks will only terminate upon
 * {@code shutdownNow}, or after setting the policy to
 * {@code false} when already shutdown.
 * This value is by default {@code true}.
 *
 * @param value if {@code true}, execute after shutdown, else don't
 * @see #getExecuteExistingDelayedTasksAfterShutdownPolicy
 */
public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean value) {
  executeExistingDelayedTasksAfterShutdown = value;
  if (!value && isShutdown())
    onShutdown();
}

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

/**
 * Sets the policy on whether to continue executing existing
 * periodic tasks even when this executor has been {@code shutdown}.
 * In this case, these tasks will only terminate upon
 * {@code shutdownNow} or after setting the policy to
 * {@code false} when already shutdown.
 * This value is by default {@code false}.
 *
 * @param value if {@code true}, continue after shutdown, else don't
 * @see #getContinueExistingPeriodicTasksAfterShutdownPolicy
 */
public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value) {
  continueExistingPeriodicTasksAfterShutdown = value;
  if (!value && isShutdown())
    onShutdown();
}

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

public JCQueue(String queueName, int size, int overflowLimit, int producerBatchSz, IWaitStrategy backPressureWaitStrategy,
        String topologyId, String componentId, Integer taskId, int port) {
  this.queueName = queueName;
  this.overflowLimit = overflowLimit;
  this.recvQueue = new MpscArrayQueue<>(size);
  this.overflowQ = new MpscUnboundedArrayQueue<>(size);
  this.metrics = new JCQueue.QueueMetrics();
  this.jcMetrics = StormMetricRegistry.jcMetrics(queueName, topologyId, componentId, taskId, port);
  //The batch size can be no larger than half the full recvQueue size, to avoid contention issues.
  this.producerBatchSz = Math.max(1, Math.min(producerBatchSz, size / 2));
  this.backPressureWaitStrategy = backPressureWaitStrategy;
  if (!METRICS_REPORTER_EXECUTOR.isShutdown()) {
    METRICS_REPORTER_EXECUTOR.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        jcMetrics.set(metrics);
      }
    }, 15, 15, TimeUnit.SECONDS);
  }
}

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

@Override
public void awaitPendingAfterQuiesce() throws InterruptedException {
  if (!timerService.isTerminated()) {
    Preconditions.checkState(timerService.isTerminating() || timerService.isShutdown());
    // await forever (almost)
    timerService.awaitTermination(365L, TimeUnit.DAYS);
  }
}

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

public synchronized void supervise(LifecycleAware lifecycleAware,
  SupervisorPolicy policy, LifecycleState desiredState) {
 if (this.monitorService.isShutdown()
   || this.monitorService.isTerminated()
   || this.monitorService.isTerminating()) {
  throw new FlumeException("Supervise called on " + lifecycleAware + " " +
    "after shutdown has been initiated. " + lifecycleAware + " will not" +
    " be started");
 }
 Preconditions.checkState(!supervisedProcesses.containsKey(lifecycleAware),
   "Refusing to supervise " + lifecycleAware + " more than once");
 if (logger.isDebugEnabled()) {
  logger.debug("Supervising service:{} policy:{} desiredState:{}",
    new Object[] { lifecycleAware, policy, desiredState });
 }
 Supervisoree process = new Supervisoree();
 process.status = new Status();
 process.policy = policy;
 process.status.desiredState = desiredState;
 process.status.error = false;
 MonitorRunnable monitorRunnable = new MonitorRunnable();
 monitorRunnable.lifecycleAware = lifecycleAware;
 monitorRunnable.supervisoree = process;
 monitorRunnable.monitorService = monitorService;
 supervisedProcesses.put(lifecycleAware, process);
 ScheduledFuture<?> future = monitorService.scheduleWithFixedDelay(
   monitorRunnable, 0, 3, TimeUnit.SECONDS);
 monitorFutures.put(lifecycleAware, future);
}

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

/**
 * Main execution method for delayed or periodic tasks.  If pool
 * is shut down, rejects the task. Otherwise adds task to queue
 * and starts a thread, if necessary, to run it.  (We cannot
 * prestart the thread to run the task because the task (probably)
 * shouldn't be run yet.)  If the pool is shut down while the task
 * is being added, cancel and remove it if required by state and
 * run-after-shutdown parameters.
 *
 * @param task the task
 */
private void delayedExecute(RunnableScheduledFuture<?> task) {
  if (isShutdown())
    reject(task);
  else {
    super.getQueue().add(task);
    if (isShutdown() &&
      !canRunInCurrentRunState(task.isPeriodic()) &&
      remove(task))
      task.cancel(false);
    else
      ensurePrestart();
  }
}

代码示例来源:origin: kiegroup/jbpm

@Override
public void internalSchedule(TimerJobInstance timerJobInstance) {
  if (scheduler.isShutdown()) {
    return;
  }
  Date date = timerJobInstance.getTrigger().hasNextFireTime();
  Callable<Void> item = (Callable<Void>) timerJobInstance;
  GlobalJDKJobHandle jobHandle = (GlobalJDKJobHandle) timerJobInstance.getJobHandle();
  long then = date.getTime();
  long now = System.currentTimeMillis();
  ScheduledFuture<Void> future = null;
  if ( then >= now ) {
    future = scheduler.schedule( new RetriggerCallable(scheduler, item),
                   then - now,
                   TimeUnit.MILLISECONDS );
  } else {
    future = scheduler.schedule( new RetriggerCallable(scheduler, item),
                   0,
                   TimeUnit.MILLISECONDS );
  }
  jobHandle.setFuture( future );
  globalTimerService.getTimerJobFactoryManager().addTimerJobInstance( timerJobInstance );
}

代码示例来源:origin: twitter/distributedlog

@Override
  public void run() {
    try {
      int txid = 1;
      for (long i = 0; i < numSegments; i++) {
        long start = txid;
        BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
        for (long j = 1; j <= segmentSize; j++) {
          writer.write(DLMTestUtil.getLargeLogRecordInstance(txid++));
          if ((i == 0) && (j == 1)) {
            latch.countDown();
          }
        }
        writer.closeAndComplete();
        Thread.sleep(100);
      }
    } catch (Exception exc) {
      if (!executor.isShutdown()) {
        currentThread.interrupt();
      }
    }
  }
}, 0, TimeUnit.MILLISECONDS);

代码示例来源:origin: PipelineAI/pipeline

@Test
public void testReset() {
  HystrixTimer timer = HystrixTimer.getInstance();
  TestListener l1 = new TestListener(50, "A");
  timer.addTimerListener(l1);
  ScheduledExecutor ex = timer.executor.get();
  assertFalse(ex.executor.isShutdown());
  // perform reset which should shut it down
  HystrixTimer.reset();
  assertTrue(ex.executor.isShutdown());
  assertNull(timer.executor.get());
  // assert it starts up again on use
  TestListener l2 = new TestListener(50, "A");
  timer.addTimerListener(l2);
  ScheduledExecutor ex2 = timer.executor.get();
  assertFalse(ex2.executor.isShutdown());
  // reset again to shutdown what we just started
  HystrixTimer.reset();
  // try resetting again to make sure it's idempotent (ie. doesn't blow up on an NPE)
  HystrixTimer.reset();
}

代码示例来源:origin: twitter/distributedlog

if (!executor.isShutdown()) {
  currentThread.interrupt();

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Tests whether a default executor service is created if no service is
 * provided.
 */
@Test
public void testInitDefaultService() {
  final TimedSemaphore semaphore = new TimedSemaphore(PERIOD, UNIT, LIMIT);
  final ScheduledThreadPoolExecutor exec = (ScheduledThreadPoolExecutor) semaphore
      .getExecutorService();
  assertFalse("Wrong periodic task policy", exec
      .getContinueExistingPeriodicTasksAfterShutdownPolicy());
  assertFalse("Wrong delayed task policy", exec
      .getExecuteExistingDelayedTasksAfterShutdownPolicy());
  assertFalse("Already shutdown", exec.isShutdown());
  semaphore.shutdown();
}

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

@Override
public Result next() {
 if (count <= 0)
  throw new NoSuchElementException();
 try {
  Result result = rq.poll(1, TimeUnit.SECONDS);
  while (result == null) {
   if (threadPool.isShutdown()) {
    throw new NoSuchElementException("ConditionalWriter closed");
   }
   result = rq.poll(1, TimeUnit.SECONDS);
  }
  count--;
  return result;
 } catch (InterruptedException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: ebean-orm/ebean

/**
  * Shutdown this thread pool nicely if possible.
  * <p>
  * This will wait a maximum of 20 seconds before terminating any threads still
  * working.
  * </p>
  */
 @Override
 public void shutdown() {
  synchronized (this) {
   if (super.isShutdown()) {
    logger.debug("DaemonScheduleThreadPool {} already shut down", namePrefix);
    return;
   }
   try {
    logger.debug("DaemonScheduleThreadPool {} shutting down...", namePrefix);
    super.shutdown();
    if (!super.awaitTermination(shutdownWaitSeconds, TimeUnit.SECONDS)) {
     logger.info("DaemonScheduleThreadPool shut down timeout exceeded. Terminating running threads.");
     super.shutdownNow();
    }

   } catch (Exception e) {
    logger.error("Error during shutdown of " + namePrefix, e);
    e.printStackTrace();
   }
  }
 }
}

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

/**
 * @return true when the service is shutdown and thus cannot be used anymore
 */
public boolean isShutdown() {
 return scheduler.isShutdown();
}

代码示例来源:origin: org.apache.flink/flink-streaming-java_2.11

@Override
public void awaitPendingAfterQuiesce() throws InterruptedException {
  if (!timerService.isTerminated()) {
    Preconditions.checkState(timerService.isTerminating() || timerService.isShutdown());
    // await forever (almost)
    timerService.awaitTermination(365L, TimeUnit.DAYS);
  }
}

相关文章

微信公众号

最新文章

更多

ScheduledThreadPoolExecutor类方法