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

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

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

ScheduledThreadPoolExecutor.getThreadFactory介绍

暂无

代码示例

代码示例来源:origin: google/guava

public void testGetScheduledExitingExecutorService_shutdownHookRegistered()
  throws InterruptedException {
 TestApplication application = new TestApplication();
 ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
 ThreadFactory threadFactory = mock(ThreadFactory.class);
 when(executor.getThreadFactory()).thenReturn(threadFactory);
 ScheduledExecutorService unused = application.getExitingScheduledExecutorService(executor);
 application.shutdown();
 verify(executor).shutdown();
}

代码示例来源:origin: google/guava

public void testGetExitingScheduledExecutorService_executorDelegatesToOriginal() {
 TestApplication application = new TestApplication();
 ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
 ThreadFactory threadFactory = mock(ThreadFactory.class);
 when(executor.getThreadFactory()).thenReturn(threadFactory);
 application.getExitingScheduledExecutorService(executor).execute(EMPTY_RUNNABLE);
 verify(executor).execute(EMPTY_RUNNABLE);
}

代码示例来源:origin: google/guava

public void testGetExitingScheduledExecutorService_executorSetToUseDaemonThreads() {
 TestApplication application = new TestApplication();
 ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
 assertNotNull(application.getExitingScheduledExecutorService(executor));
 assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}

代码示例来源:origin: dernasherbrezon/r2cloud

public static void shutdown(ScheduledExecutorService executor, long timeoutMillis) {
  if (executor == null) {
    return;
  }
  executor.shutdownNow();
  boolean cleanlyTerminated;
  try {
    cleanlyTerminated = executor.awaitTermination(timeoutMillis, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    cleanlyTerminated = executor.isTerminated();
  }
  if (!cleanlyTerminated) {
    String threadpoolName;
    if (executor instanceof ScheduledThreadPoolExecutor) {
      ThreadFactory factory = ((ScheduledThreadPoolExecutor) executor).getThreadFactory();
      if (factory instanceof NamingThreadFactory) {
        NamingThreadFactory namingFactory = (NamingThreadFactory) factory;
        threadpoolName = namingFactory.getPrefix();
      } else {
        threadpoolName = "unknown[" + factory.getClass().getSimpleName() + "]";
      }
    } else {
      threadpoolName = "unknown[" + executor.getClass().getSimpleName() + "]";
    }
    LOG.error("executor did not terminate in the specified time: " + threadpoolName);
  }
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * Converts the given ScheduledThreadPoolExecutor into a
 * ScheduledExecutorService that exits when the application is complete.  It
 * does so by using daemon threads and adding a shutdown hook to wait for
 * their completion.
 *
 * <p>This is mainly for fixed thread pools.
 * See {@link Executors#newScheduledThreadPool(int)}.
 *
 * @param executor the executor to modify to make sure it exits when the
 *        application is finished
 * @param terminationTimeout how long to wait for the executor to
 *        finish before terminating the JVM
 * @param timeUnit unit of time for the time parameter
 * @return an unmodifiable version of the input which will not hang the JVM
 */
@Beta
public static ScheduledExecutorService getExitingScheduledExecutorService(
  ScheduledThreadPoolExecutor executor, long terminationTimeout,
  TimeUnit timeUnit) {
 executor.setThreadFactory(new ThreadFactoryBuilder()
   .setDaemon(true)
   .setThreadFactory(executor.getThreadFactory())
   .build());
 ScheduledExecutorService service =
   Executors.unconfigurableScheduledExecutorService(executor);
 addDelayedShutdownHook(service, terminationTimeout, timeUnit);
 return service;
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Converts the given ScheduledThreadPoolExecutor into a
 * ScheduledExecutorService that exits when the application is complete.  It
 * does so by using daemon threads and adding a shutdown hook to wait for
 * their completion.
 *
 * <p>This is mainly for fixed thread pools.
 * See {@link Executors#newScheduledThreadPool(int)}.
 *
 * @param executor the executor to modify to make sure it exits when the
 *        application is finished
 * @param terminationTimeout how long to wait for the executor to
 *        finish before terminating the JVM
 * @param timeUnit unit of time for the time parameter
 * @return an unmodifiable version of the input which will not hang the JVM
 */
public static ScheduledExecutorService getExitingScheduledExecutorService(
  ScheduledThreadPoolExecutor executor, long terminationTimeout,
  TimeUnit timeUnit) {
 executor.setThreadFactory(new ThreadFactoryBuilder()
   .setDaemon(true)
   .setThreadFactory(executor.getThreadFactory())
   .build());
 ScheduledExecutorService service =
   Executors.unconfigurableScheduledExecutorService(executor);
 addDelayedShutdownHook(service, terminationTimeout, timeUnit);
 return service;
}

代码示例来源:origin: com.google.guava/guava-tests

public void testGetScheduledExitingExecutorService_shutdownHookRegistered()
  throws InterruptedException {
 TestApplication application = new TestApplication();
 ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
 ThreadFactory threadFactory = mock(ThreadFactory.class);
 when(executor.getThreadFactory()).thenReturn(threadFactory);
 ScheduledExecutorService unused = application.getExitingScheduledExecutorService(executor);
 application.shutdown();
 verify(executor).shutdown();
}

代码示例来源:origin: com.google.guava/guava-tests

public void testGetExitingScheduledExecutorService_executorDelegatesToOriginal() {
 TestApplication application = new TestApplication();
 ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
 ThreadFactory threadFactory = mock(ThreadFactory.class);
 when(executor.getThreadFactory()).thenReturn(threadFactory);
 application.getExitingScheduledExecutorService(executor).execute(EMPTY_RUNNABLE);
 verify(executor).execute(EMPTY_RUNNABLE);
}

代码示例来源:origin: com.google.guava/guava-tests

public void testGetExitingScheduledExecutorService_executorSetToUseDaemonThreads() {
 TestApplication application = new TestApplication();
 ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
 assertNotNull(application.getExitingScheduledExecutorService(executor));
 assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache-jdbc

/**
 * Converts the given ScheduledThreadPoolExecutor into a
 * ScheduledExecutorService that exits when the application is complete.  It
 * does so by using daemon threads and adding a shutdown hook to wait for
 * their completion.
 *
 * <p>This is mainly for fixed thread pools.
 * See {@link Executors#newScheduledThreadPool(int)}.
 *
 * @param executor the executor to modify to make sure it exits when the
 *        application is finished
 * @param terminationTimeout how long to wait for the executor to
 *        finish before terminating the JVM
 * @param timeUnit unit of time for the time parameter
 * @return an unmodifiable version of the input which will not hang the JVM
 */
@Beta
public static ScheduledExecutorService getExitingScheduledExecutorService(
  ScheduledThreadPoolExecutor executor, long terminationTimeout,
  TimeUnit timeUnit) {
 executor.setThreadFactory(new ThreadFactoryBuilder()
   .setDaemon(true)
   .setThreadFactory(executor.getThreadFactory())
   .build());
 ScheduledExecutorService service =
   Executors.unconfigurableScheduledExecutorService(executor);
 addDelayedShutdownHook(service, terminationTimeout, timeUnit);
 return service;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Converts the given ScheduledThreadPoolExecutor into a
 * ScheduledExecutorService that exits when the application is complete.  It
 * does so by using daemon threads and adding a shutdown hook to wait for
 * their completion.
 *
 * <p>This is mainly for fixed thread pools.
 * See {@link Executors#newScheduledThreadPool(int)}.
 *
 * @param executor the executor to modify to make sure it exits when the
 *        application is finished
 * @param terminationTimeout how long to wait for the executor to
 *        finish before terminating the JVM
 * @param timeUnit unit of time for the time parameter
 * @return an unmodifiable version of the input which will not hang the JVM
 */
@Beta
public static ScheduledExecutorService getExitingScheduledExecutorService(
  ScheduledThreadPoolExecutor executor, long terminationTimeout,
  TimeUnit timeUnit) {
 executor.setThreadFactory(new ThreadFactoryBuilder()
   .setDaemon(true)
   .setThreadFactory(executor.getThreadFactory())
   .build());
 ScheduledExecutorService service =
   Executors.unconfigurableScheduledExecutorService(executor);
 addDelayedShutdownHook(service, terminationTimeout, timeUnit);
 return service;
}

代码示例来源:origin: io.prestosql.hive/hive-apache-jdbc

/**
 * Converts the given ScheduledThreadPoolExecutor into a
 * ScheduledExecutorService that exits when the application is complete.  It
 * does so by using daemon threads and adding a shutdown hook to wait for
 * their completion.
 *
 * <p>This is mainly for fixed thread pools.
 * See {@link Executors#newScheduledThreadPool(int)}.
 *
 * @param executor the executor to modify to make sure it exits when the
 *        application is finished
 * @param terminationTimeout how long to wait for the executor to
 *        finish before terminating the JVM
 * @param timeUnit unit of time for the time parameter
 * @return an unmodifiable version of the input which will not hang the JVM
 */
@Beta
public static ScheduledExecutorService getExitingScheduledExecutorService(
  ScheduledThreadPoolExecutor executor, long terminationTimeout,
  TimeUnit timeUnit) {
 executor.setThreadFactory(new ThreadFactoryBuilder()
   .setDaemon(true)
   .setThreadFactory(executor.getThreadFactory())
   .build());
 ScheduledExecutorService service =
   Executors.unconfigurableScheduledExecutorService(executor);
 addDelayedShutdownHook(service, terminationTimeout, timeUnit);
 return service;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Converts the given ScheduledThreadPoolExecutor into a
 * ScheduledExecutorService that exits when the application is complete.  It
 * does so by using daemon threads and adding a shutdown hook to wait for
 * their completion.
 *
 * <p>This is mainly for fixed thread pools.
 * See {@link Executors#newScheduledThreadPool(int)}.
 *
 * @param executor the executor to modify to make sure it exits when the
 *        application is finished
 * @param terminationTimeout how long to wait for the executor to
 *        finish before terminating the JVM
 * @param timeUnit unit of time for the time parameter
 * @return an unmodifiable version of the input which will not hang the JVM
 */
@Beta
public static ScheduledExecutorService getExitingScheduledExecutorService(
  ScheduledThreadPoolExecutor executor, long terminationTimeout,
  TimeUnit timeUnit) {
 executor.setThreadFactory(new ThreadFactoryBuilder()
   .setDaemon(true)
   .setThreadFactory(executor.getThreadFactory())
   .build());
 ScheduledExecutorService service =
   Executors.unconfigurableScheduledExecutorService(executor);
 addDelayedShutdownHook(service, terminationTimeout, timeUnit);
 return service;
}

相关文章

微信公众号

最新文章

更多

ScheduledThreadPoolExecutor类方法