List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory)
From source file:org.openscada.hd.server.storage.master.hds.StorageManager.java
public StorageManager(final BundleContext context, final DataFilePool pool) { super(makeBase(context)); this.context = context; this.pool = pool; this.updateExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("HDSUpdate")); this.eventExecutor = new ScheduledExportedExecutorService( "org.openscada.hd.server.storage.master.hds.events", 1); initialize();//w w w . j a v a 2s . c om }
From source file:com.twitter.distributedlog.feature.DynamicConfigurationFeatureProvider.java
public DynamicConfigurationFeatureProvider(String rootScope, DistributedLogConfiguration conf, StatsLogger statsLogger) {/*ww w . jav a 2s . co m*/ super(rootScope, conf, statsLogger); this.features = new ConcurrentHashMap<String, SettableFeature>(); this.featuresConf = new ConcurrentBaseConfiguration(); this.executorService = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("DynamicConfigurationFeatureProvider-%d").build()); }
From source file:gobblin.cluster.ScheduledJobConfigurationManager.java
public ScheduledJobConfigurationManager(EventBus eventBus, Config config) { super(eventBus, config); this.jobSpecs = Maps.newHashMap(); this.refreshIntervalInSeconds = ConfigUtils.getLong(config, GobblinClusterConfigurationKeys.JOB_SPEC_REFRESH_INTERVAL, DEFAULT_JOB_SPEC_REFRESH_INTERVAL); this.fetchJobSpecExecutor = Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("FetchJobSpecExecutor"))); this.aliasResolver = new ClassAliasResolver<>(SpecExecutorInstanceConsumer.class); try {//from www. jav a 2s. c o m String specExecutorInstanceConsumerClassName = GobblinClusterConfigurationKeys.DEFAULT_SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS; if (config.hasPath(GobblinClusterConfigurationKeys.SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS_KEY)) { specExecutorInstanceConsumerClassName = config .getString(GobblinClusterConfigurationKeys.SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS_KEY); } LOGGER.info("Using SpecExecutorInstanceConsumer ClassNameclass name/alias " + specExecutorInstanceConsumerClassName); this.specExecutorInstanceConsumer = (SpecExecutorInstanceConsumer) ConstructorUtils.invokeConstructor( Class.forName(this.aliasResolver.resolve(specExecutorInstanceConsumerClassName)), config); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.apache.gobblin.cluster.ScheduledJobConfigurationManager.java
public ScheduledJobConfigurationManager(EventBus eventBus, Config config) { super(eventBus, config); this.jobSpecs = Maps.newHashMap(); this.refreshIntervalInSeconds = ConfigUtils.getLong(config, GobblinClusterConfigurationKeys.JOB_SPEC_REFRESH_INTERVAL, DEFAULT_JOB_SPEC_REFRESH_INTERVAL); this.fetchJobSpecExecutor = Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("FetchJobSpecExecutor"))); this.aliasResolver = new ClassAliasResolver<>(SpecConsumer.class); try {//ww w. ja v a 2s. c om String specConsumerClassName = GobblinClusterConfigurationKeys.DEFAULT_SPEC_CONSUMER_CLASS; if (config.hasPath(GobblinClusterConfigurationKeys.SPEC_CONSUMER_CLASS_KEY)) { specConsumerClassName = config.getString(GobblinClusterConfigurationKeys.SPEC_CONSUMER_CLASS_KEY); } LOGGER.info("Using SpecConsumer ClassNameclass name/alias " + specConsumerClassName); this._specConsumer = (SpecConsumer) ConstructorUtils .invokeConstructor(Class.forName(this.aliasResolver.resolve(specConsumerClassName)), config); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:io.tilt.minka.spectator.PublishSubscribeQueue.java
protected PublishSubscribeQueue(final String name, final Consumer<MessageMetadata> consumer, final long retentionMs, final CuratorFramework client, final String logId) { this.name = name; this.userListener = consumer; this.retentionMs = retentionMs; this.client = client; this.logId = logId; this.retentionExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("SPECTATOR-Queues-Retainer").build()); start(retentionMs);// w ww. j a va 2 s. c om }
From source file:de.metas.ui.web.websocket.WebSocketProducersRegistry.java
public WebSocketProducersRegistry() { scheduler = Executors.newSingleThreadScheduledExecutor(CustomizableThreadFactory.builder() .setThreadNamePrefix(getClass().getName()).setDaemon(true).build()); }
From source file:com.astamuse.asta4d.web.util.timeout.DefaultSessionAwareTimeoutDataManager.java
@Override public void start() { // init fields dataMap = new ConcurrentHashMap<>(); dataCounter = new AtomicInteger(); service = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override/*from w w w . ja va 2 s . c o m*/ public Thread newThread(Runnable r) { return new Thread(r, checkThreadName); } }); // start check thread service.scheduleAtFixedRate(new Runnable() { @Override public void run() { List<Entry<String, DataHolder>> entries = new ArrayList<>(dataMap.entrySet()); long currentTime = System.currentTimeMillis(); int removedCounter = 0; Object existing; for (Entry<String, DataHolder> entry : entries) { if (entry.getValue().isExpired(currentTime)) { existing = dataMap.remove(entry.getKey()); if (existing != null) {// we removed it successfully removedCounter++; } } } if (removedCounter > 0) { dataCounter.addAndGet(-removedCounter); } } }, expirationCheckPeriodInMilliseconds, expirationCheckPeriodInMilliseconds, TimeUnit.MILLISECONDS); }
From source file:com.opengamma.language.connector.ClientContextFactoryBean.java
private void setDefaults() { setFudgeContext(FudgeContext.GLOBAL_DEFAULT); setHousekeepingScheduler(//from w ww. j av a 2s . c om Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("Scheduler-"))); setMessageTimeout(3000); setHeartbeatTimeout(4000); setTerminationTimeout(30000); setMaxThreadsPerClient(Math.max(2, Runtime.getRuntime().availableProcessors())); setMaxClientThreads(Integer.MAX_VALUE); // messageHandler defaults to null and must be set }
From source file:org.wso2.carbon.cluster.coordinator.rdbms.RDBMSMemberEventProcessor.java
public RDBMSMemberEventProcessor(String nodeId, DataSource dataSource) { this.communicationBusContext = new RDBMSCommunicationBusContextImpl(dataSource); ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("ClusterEventReaderTask-%d") .build();/*from w w w. j a v a 2s . c om*/ this.clusterMembershipReaderTaskScheduler = Executors.newSingleThreadScheduledExecutor(namedThreadFactory); addNewListenerTask(nodeId, dataSource); }
From source file:com.reactivetechnologies.blaze.throttle.DefaultConsumerThrottler.java
@PostConstruct public void init() { if (enabled) { addCommand(new ThrottleCommand()); List<? extends Command> customCommands = loadCommands(); if (customCommands != null) { for (Command cmd : customCommands) addCommand(cmd);//from w w w . j av a 2s . com } counter = new AtomicInteger(); timer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable arg0) { Thread t = new Thread(arg0, "Throttler-timer-thread"); t.setDaemon(true); return t; } }); timer.scheduleWithFixedDelay(new MessageThrottlerTask(), 0, throttlerPeriod, TimeUnit.MILLISECONDS); log.info("Throttling enabled with period of " + throttlerPeriod + " millis"); } }