List of usage examples for java.util.concurrent Executors newSingleThreadExecutor
public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory)
From source file:com.clustercontrol.agent.SendQueue.java
/** * ????<BR>// w ww . ja v a 2s .c o m * * ?????????<BR> * ?????? * @param msg */ public boolean put(Object info) { m_log.debug("put() start : " + info.getClass().getCanonicalName()); while (!ReceiveTopic.isHistoryClear()) { m_log.debug("put() while (!ReceiveTopic.isHistoryClear()) is true"); boolean sendQueueStatus = false; ExecutorService es = null; Future<Boolean> task = null; try { String id = ""; // Executor?? SenderThreadFactory threadFactory = new SenderThreadFactory(id); es = Executors.newSingleThreadExecutor(threadFactory); // Queue?? // ?Queue?????????????????? // Future.get()???????? m_log.debug("put() submit"); task = es.submit(new Sender(info)); sendQueueStatus = task.get(SEND_TIMEOUT, TimeUnit.MILLISECONDS); } catch (Exception e) { // Queue?????????????Future.get()??????? // ???? // ? m_log.warn("put() : Failed to connect to MGR " + e.getMessage(), e); } finally { // if (task != null) { task.cancel(true); } if (es != null) { es.shutdown(); } m_log.debug("put() end : " + info.getClass().getCanonicalName()); } // ??????????sleep???? // Queue???????? if (sendQueueStatus) { m_log.debug("put() return true : " + info.getClass().getCanonicalName()); return true; } else { // sleep???QueueConnection?QueueSession ?? try { m_log.debug("put() reput interval sleep: " + m_sendQueueReconnectionInterval + " sec"); Thread.sleep(m_sendQueueReconnectionInterval); } catch (InterruptedException e1) { m_log.error("put() reput interval sleep: ", e1); } } } // End While Loop return false; }
From source file:io.pivotal.receptor.events.EventDispatcher.java
public EventDispatcher(String url) { Assert.hasText(url, "URL is required"); this.url = url; this.backgroundExecutor = Executors .newSingleThreadExecutor(new CustomizableThreadFactory("receptor-event-subscriber-")); this.dispatchingExecutor = Executors .newCachedThreadPool(new CustomizableThreadFactory("receptor-event-dispatcher-")); }
From source file:com.ebay.cloud.cms.sysmgmt.monitor.metrics.MongoMetric.java
public MongoMetric(MongoDataSource dataSource, int period, int waitLimit) { this.dataSource = dataSource; this.period = period; this.listWaitPeroid = waitLimit; executor = Executors.newSingleThreadExecutor(DaemonThreadFactory.getInstance()); snapshot();// www. j a v a 2s . co m }
From source file:net.sf.jacclog.service.importer.internal.queue.LogFileQueueImporterObserver.java
public LogFileQueueImporterObserver(final LogEntryImportService<ReadonlyLogEntry> service) { if (service == null) { throw new IllegalArgumentException("Argument 'service' must be not null."); }//from w w w . j av a2 s . c o m this.service = service; final BasicThreadFactory factory = new BasicThreadFactory.Builder() // attributes .namingPattern("file-importer-%d").daemon(true).priority(Thread.MIN_PRIORITY) .uncaughtExceptionHandler(new UncaughtExceptionHandler()).build(); executor = Executors.newSingleThreadExecutor(factory); }
From source file:com.twitter.hbc.httpclient.BasicClientTest.java
public BasicClientTest() { ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("hosebird-client-unit-test-%d").build(); executorService = Executors.newSingleThreadExecutor(threadFactory); }
From source file:com.techcavern.pircbotz.hooks.managers.BackgroundListenerManager.java
public void addListener(Listener listener, boolean isBackground) { if (!isBackground) super.addListener(listener); else {/*ww w . j av a2s. c o m*/ BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("backgroundPool" + managerNumber + "-backgroundThread" + backgroundCount.getAndIncrement() + "-%d").daemon(true) .build(); backgroundListeners.put(listener, Executors.newSingleThreadExecutor(factory)); } }
From source file:com.clustercontrol.winsyslog.SyslogReceiver.java
private ExecutorService createExecutorService(final String name) { ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override/*from w ww. j a v a 2 s . com*/ public Thread newThread(Runnable r) { return new Thread(r, name); } }); return executor; }
From source file:gobblin.cluster.StreamingJobConfigurationManager.java
public StreamingJobConfigurationManager(EventBus eventBus, Config config, MutableJobCatalog jobCatalog) { super(eventBus, config); this.stopTimeoutSeconds = ConfigUtils.getLong(config, GobblinClusterConfigurationKeys.STOP_TIMEOUT_SECONDS, GobblinClusterConfigurationKeys.DEFAULT_STOP_TIMEOUT_SECONDS); this.fetchJobSpecExecutor = Executors.newSingleThreadExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("FetchJobSpecExecutor"))); String specExecutorInstanceConsumerClassName = ConfigUtils.getString(config, GobblinClusterConfigurationKeys.SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS_KEY, GobblinClusterConfigurationKeys.DEFAULT_STREAMING_SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS); LOGGER.info("Using SpecExecutorInstanceConsumer ClassNameclass name/alias " + specExecutorInstanceConsumerClassName); try {//from w ww . j a va2 s . c o m ClassAliasResolver<SpecExecutorInstanceConsumer> aliasResolver = new ClassAliasResolver<>( SpecExecutorInstanceConsumer.class); this.specExecutorInstanceConsumer = (SpecExecutorInstanceConsumer) GobblinConstructorUtils .invokeFirstConstructor( Class.forName(aliasResolver.resolve(specExecutorInstanceConsumerClassName)), ImmutableList.<Object>of(config, jobCatalog), ImmutableList.<Object>of(config)); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException( "Could not construct SpecExecutorInstanceConsumer " + specExecutorInstanceConsumerClassName, e); } }
From source file:de.ks.flatadocdb.index.GlobalIndex.java
public GlobalIndex(Repository repository, MetaModel metaModel) { this(repository, metaModel, Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).build())); }
From source file:ch.algotrader.marketdata.MarketDataSubscriber.java
public MarketDataSubscriber(final EventDispatcher eventDispatcher, final LookupService lookupService, final MarketDataService marketDataService, final Map<String, String> sessionToFeedTypeMap) { Validate.notNull(eventDispatcher, "EventDispatcher is null"); Validate.notNull(lookupService, "LookupService is null"); Validate.notNull(marketDataService, "MarketDataService is null"); this.eventDispatcher = eventDispatcher; this.lookupService = lookupService; this.marketDataService = marketDataService; this.sessionToFeedTypeMap = new ConcurrentHashMap<>(sessionToFeedTypeMap); this.executorService = Executors .newSingleThreadExecutor(new BasicThreadFactory("Market-data-subscriber-thread", true)); }