List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory)
From source file:com.ctriposs.r2.transport.http.client.HttpClientFactory.java
/** * Construct a new instance using the specified filter chain. * * @param filters the {@link FilterChain} shared by all Clients created by this factory. *//*from w w w . j a va 2s .c o m*/ public HttpClientFactory(FilterChain filters) { // TODO Disable Netty's thread renaming so that the names below are the ones that actually // show up in log messages; need to coordinate with Espresso team (who also have netty threads) this(filters, new NioClientSocketChannelFactory( Executors.newCachedThreadPool(new NamedThreadFactory("R2 Netty IO Boss")), Executors.newCachedThreadPool(new NamedThreadFactory("R2 Netty IO Worker"))), true, Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("R2 Netty Scheduler")), true); }
From source file:org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.java
@Override public void initialize(final UserGroupProviderInitializationContext initializationContext) throws SecurityProviderCreationException { ldapSync = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { final ThreadFactory factory = Executors.defaultThreadFactory(); @Override/*ww w . j a v a2 s. c o m*/ public Thread newThread(Runnable r) { final Thread thread = factory.newThread(r); thread.setName(String.format("%s (%s) - background sync thread", getClass().getSimpleName(), initializationContext.getIdentifier())); return thread; } }); }
From source file:org.apache.kylin.dict.lookup.cache.RocksDBLookupTableCache.java
private void initExecutors() { this.cacheBuildExecutor = new ThreadPoolExecutor(0, 50, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("lookup-cache-build-thread")); this.cacheStateCheckExecutor = Executors .newSingleThreadScheduledExecutor(new NamedThreadFactory("lookup-cache-state-checker")); cacheStateCheckExecutor.scheduleAtFixedRate(cacheStateChecker, 10, 10 * 60, TimeUnit.SECONDS); // check every 10 minutes }
From source file:com.linkedin.r2.transport.http.client.HttpClientFactory.java
/** * Construct a new instance using the specified filter chain. * * @param filters the {@link FilterChain} shared by all Clients created by this factory. *//*from ww w . ja va 2s. c o m*/ public HttpClientFactory(FilterChain filters) { // TODO Disable Netty's thread renaming so that the names below are the ones that actually // show up in log messages; need to coordinate with Espresso team (who also have netty threads) this(filters, new NioEventLoopGroup(0 /* use default settings */, new NamedThreadFactory("R2 Nio Event Loop")), true, Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("R2 Netty Scheduler")), true); }
From source file:org.apache.bookkeeper.stream.common.Scheduler.java
private Scheduler(String name, int numExecutors) { Preconditions.checkArgument(StringUtils.isNotBlank(name), "Require a not-blank scheduler name"); Preconditions.checkArgument(numExecutors > 0, "Require positive value for num executors"); this.name = name; this.executors = new ListeningScheduledExecutorService[numExecutors]; for (int i = 0; i < numExecutors; i++) { StringBuilder sb = new StringBuilder(name); sb.append("-executor-").append(i).append("-%d"); ThreadFactoryBuilder tfb = new ThreadFactoryBuilder().setNameFormat(sb.toString()); executors[i] = MoreExecutors//ww w .j av a2s . co m .listeningDecorator(Executors.newSingleThreadScheduledExecutor(tfb.build())); } this.random = new Random(System.currentTimeMillis()); }
From source file:com.yahoo.pulsar.broker.service.BrokerService.java
public BrokerService(PulsarService pulsar) throws Exception { this.pulsar = pulsar; this.managedLedgerFactory = pulsar.getManagedLedgerFactory(); this.port = new URI(pulsar.getBrokerServiceUrl()).getPort(); this.tlsPort = new URI(pulsar.getBrokerServiceUrlTls()).getPort(); this.topics = new ConcurrentOpenHashMap<>(); this.replicationClients = new ConcurrentOpenHashMap<>(); this.keepAliveIntervalSeconds = pulsar.getConfiguration().getKeepAliveIntervalSeconds(); this.multiLayerTopicsMap = new ConcurrentOpenHashMap<>(); this.pulsarStats = new PulsarStats(pulsar); this.offlineTopicStatCache = new ConcurrentOpenHashMap<>(); final DefaultThreadFactory acceptorThreadFactory = new DefaultThreadFactory("pulsar-acceptor"); final DefaultThreadFactory workersThreadFactory = new DefaultThreadFactory("pulsar-io"); final int numThreads = Runtime.getRuntime().availableProcessors() * 2; log.info("Using {} threads for broker service IO", numThreads); EventLoopGroup acceptorEventLoop, workersEventLoop; if (SystemUtils.IS_OS_LINUX) { try {// w ww . j a v a 2s . c om acceptorEventLoop = new EpollEventLoopGroup(1, acceptorThreadFactory); workersEventLoop = new EpollEventLoopGroup(numThreads, workersThreadFactory); } catch (UnsatisfiedLinkError e) { acceptorEventLoop = new NioEventLoopGroup(1, acceptorThreadFactory); workersEventLoop = new NioEventLoopGroup(numThreads, workersThreadFactory); } } else { acceptorEventLoop = new NioEventLoopGroup(1, acceptorThreadFactory); workersEventLoop = new NioEventLoopGroup(numThreads, workersThreadFactory); } this.acceptorGroup = acceptorEventLoop; this.workerGroup = workersEventLoop; this.statsUpdater = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-stats-updater")); if (pulsar.getConfiguration().isAuthorizationEnabled()) { this.authorizationManager = new AuthorizationManager(pulsar.getConfiguration(), pulsar.getConfigurationCache()); } if (pulsar.getConfigurationCache() != null) { pulsar.getConfigurationCache().policiesCache().registerListener(this); } this.inactivityMonitor = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-inactivity-monitor")); this.messageExpiryMonitor = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-msg-expiry-monitor")); this.backlogQuotaManager = new BacklogQuotaManager(pulsar); this.backlogQuotaChecker = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-backlog-quota-checker")); this.authenticationService = new AuthenticationService(pulsar.getConfiguration()); PersistentReplicator.setReplicatorQueueSize(pulsar.getConfiguration().getReplicationProducerQueueSize()); }
From source file:org.mule.module.launcher.DeploymentDirectoryWatcher.java
private void scheduleChangeMonitor() { final int reloadIntervalMs = getChangesCheckIntervalMs(); artifactDirMonitorTimer = Executors .newSingleThreadScheduledExecutor(new ArtifactDeployerMonitorThreadFactory()); artifactDirMonitorTimer.scheduleWithFixedDelay(this, 0, reloadIntervalMs, TimeUnit.MILLISECONDS); if (logger.isInfoEnabled()) { logger.info(miniSplash(String.format("Mule is up and kicking (every %dms)", reloadIntervalMs))); }/*from w w w .j a va 2s. c o m*/ }
From source file:io.atomix.cluster.messaging.impl.NettyMessagingService.java
@Override public CompletableFuture<MessagingService> start() { getTlsParameters();//from w w w. j a v a 2 s . c o m if (started.get()) { log.warn("Already running at local address: {}", localAddress); return CompletableFuture.completedFuture(this); } initEventLoopGroup(); return startAcceptingConnections().thenRun(() -> { timeoutExecutor = Executors .newSingleThreadScheduledExecutor(namedThreads("netty-messaging-timeout-%d", log)); timeoutFuture = timeoutExecutor.scheduleAtFixedRate(this::timeoutAllCallbacks, TIMEOUT_INTERVAL, TIMEOUT_INTERVAL, TimeUnit.MILLISECONDS); started.set(true); log.info("Started"); }).thenApply(v -> this); }
From source file:org.opennms.netmgt.eventd.mock.MockEventIpcManager.java
ScheduledExecutorService getScheduler() { if (m_scheduler == null) { m_scheduler = Executors.newSingleThreadScheduledExecutor( new LogPreservingThreadFactory(getClass().getSimpleName(), 1, false)); }//w ww . ja v a 2 s . c o m return m_scheduler; }
From source file:org.mule.module.launcher.MuleDeploymentService.java
protected void scheduleChangeMonitor(File appsDir) { final int reloadIntervalMs = DEFAULT_CHANGES_CHECK_INTERVAL_MS; appDirMonitorTimer = Executors.newSingleThreadScheduledExecutor(new AppDeployerMonitorThreadFactory()); appDirMonitorTimer.scheduleWithFixedDelay(new AppDirWatcher(appsDir), 0, reloadIntervalMs, TimeUnit.MILLISECONDS); if (logger.isInfoEnabled()) { logger.info(miniSplash(String.format("Mule is up and kicking (every %dms)", reloadIntervalMs))); }//from w w w . j a va 2 s .c o m }