Java Code Examples for java.util.concurrent.ScheduledThreadPoolExecutor#setThreadFactory()
The following examples show how to use
java.util.concurrent.ScheduledThreadPoolExecutor#setThreadFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginOutputAsyncerImpl.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@Inject public PluginOutputAsyncerImpl(@NotNull final ShutdownHooks shutdownHooks) { this.shutdownHooks = shutdownHooks; final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); //enable removing canceled tasks from the executor queue executor.setRemoveOnCancelPolicy(true); executor.setThreadFactory(ThreadFactoryUtil.create("extension-timeout-executor-%d")); //for instrumentation (metrics) scheduledExecutor = executor; }
Example 2
Source File: ExecutorScheduler.java From lite-pool with Apache License 2.0 | 5 votes |
protected void doStart() throws Exception { // 1 super.doStart(); // 2 this.factory.compareAndSet(null, new XThreadFactory(name, false)); ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(this.corePoolSize); s.setRemoveOnCancelPolicy(true); s.setThreadFactory(factory.get()); executor.set(s); }
Example 3
Source File: ScheduledExecutorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() throws InterruptedException { ThreadFactory threadFactory = new SimpleThreadFactory(); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { p.setThreadFactory(threadFactory); assertSame(threadFactory, p.getThreadFactory()); } }
Example 4
Source File: ScheduledExecutorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.setThreadFactory(null); shouldThrow(); } catch (NullPointerException success) {} } }
Example 5
Source File: CustomSchedulingConfiguration.java From booties with Apache License 2.0 | 5 votes |
@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; }
Example 6
Source File: ScheduledExecutorTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() throws InterruptedException { ThreadFactory threadFactory = new SimpleThreadFactory(); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { p.setThreadFactory(threadFactory); assertSame(threadFactory, p.getThreadFactory()); } }
Example 7
Source File: ScheduledExecutorTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.setThreadFactory(null); shouldThrow(); } catch (NullPointerException success) {} } }
Example 8
Source File: ServiceQueue.java From asteria-3.0 with GNU General Public License v3.0 | 5 votes |
/** * Creates and configures a new {@link ScheduledExecutorService} with a * timeout value of {@code seconds}. If the timeout value is below or equal * to zero then the returned executor will never timeout. * * @return the newly created and configured executor service. */ private static ScheduledExecutorService createServiceExecutor(long seconds) { Preconditions.checkArgument(seconds >= 0, "The timeout value must be equal to or greater than 0!"); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); executor.setRejectedExecutionHandler(new CallerRunsPolicy()); executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("ServiceQueueThread").build()); if (seconds > 0) { executor.setKeepAliveTime(seconds, TimeUnit.SECONDS); executor.allowCoreThreadTimeOut(true); } return executor; }