List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory)
From source file:org.killbill.bus.DefaultPersistentBus.java
@Inject public DefaultPersistentBus(@Named(QUEUE_NAME) final IDBI dbi, final Clock clock, final PersistentBusConfig config, final MetricRegistry metricRegistry, final DatabaseTransactionNotificationApi databaseTransactionNotificationApi) { super("Bus", Executors.newFixedThreadPool(config.getNbThreads(), new ThreadFactory() { @Override//from w ww. ja v a2s . c o m public Thread newThread(final Runnable r) { return new Thread(new ThreadGroup(EVENT_BUS_GROUP_NAME), r, config.getTableName() + "-th"); } }), config.getNbThreads(), config); final PersistentBusSqlDao sqlDao = dbi.onDemand(PersistentBusSqlDao.class); this.clock = clock; final String dbBackedQId = "bus-" + config.getTableName(); this.dao = new DBBackedQueue<BusEventModelDao>(clock, sqlDao, config, dbBackedQId, metricRegistry, databaseTransactionNotificationApi); this.eventBusDelegate = new EventBusDelegate("Killbill EventBus"); this.dispatchTimer = metricRegistry.timer(MetricRegistry.name(DefaultPersistentBus.class, "dispatch")); this.isStarted = new AtomicBoolean(false); }
From source file:com.thinkbiganalytics.feedmgr.nifi.cache.NiFiFlowInspectorManager.java
public NiFiFlowInspectorManager(String startingProcessGroupId, NiFiFlowInspectionCallback completionCallback, int numOfThreads, boolean wait, NiFiRestClient restClient) { this.restClient = restClient; this.executorService = Executors.newFixedThreadPool( numOfThreads > 0 && numOfThreads < MAX_THREADS ? numOfThreads : DEFAULT_THREADS, flowInspectionThreadFactory); this.completionCallback = completionCallback; this.startingProcessGroupId = StringUtils.isBlank(startingProcessGroupId) ? "root" : startingProcessGroupId; this.wait = wait; this.threadCount = numOfThreads; }
From source file:io.snappydata.impl.SnappyHiveCatalog.java
public SnappyHiveCatalog() { final ThreadGroup hmsThreadGroup = LogWriterImpl.createThreadGroup(THREAD_GROUP_NAME, Misc.getI18NLogWriter());// w w w. j a va 2 s.c om ThreadFactory hmsClientThreadFactory = new ThreadFactory() { private int next = 0; @SuppressWarnings("NullableProblems") public Thread newThread(Runnable command) { Thread t = new Thread(hmsThreadGroup, command, "HiveMetaStore Client-" + next++); t.setDaemon(true); return t; } }; hmsQueriesExecutorService = Executors.newFixedThreadPool(1, hmsClientThreadFactory); // just run a task to initialize the HMC for the thread. // Assumption is that this should be outside any lock HMSQuery q = getHMSQuery(); q.resetValues(HMSQuery.INIT, null, null, true); Future<Object> ret = hmsQueriesExecutorService.submit(q); try { ret.get(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.killbill.notificationq.NotificationQueueDispatcher.java
NotificationQueueDispatcher(final Clock clock, final NotificationQueueConfig config, final IDBI dbi, final MetricRegistry metricRegistry) { super("NotificationQ", Executors.newFixedThreadPool(config.getNbThreads() + 1, new ThreadFactory() { @Override// w ww .jav a2 s. co m public Thread newThread(final Runnable r) { final Thread th = new Thread(r); th.setName(config.getTableName() + "-th"); th.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread t, final Throwable e) { log.error("Uncaught exception for thread " + t.getName(), e); } }); return th; } }), 1, config); this.clock = clock; this.config = config; this.nbProcessedEvents = new AtomicLong(); final NotificationSqlDao sqlDao = dbi.onDemand(NotificationSqlDao.class); this.dao = new DBBackedQueue<NotificationEventModelDao>(clock, sqlDao, config, "notif-" + config.getTableName(), metricRegistry, null); this.queues = new TreeMap<String, NotificationQueue>(); this.processedNotificationsSinceStart = metricRegistry.counter( MetricRegistry.name(NotificationQueueDispatcher.class, "processed-notifications-since-start")); this.perQueueProcessingTime = new HashMap<String, Histogram>(); this.pendingNotificationsQ = new LinkedBlockingQueue<NotificationEventModelDao>(config.getQueueCapacity()); this.metricRegistry = metricRegistry; this.pendingNotifications = metricRegistry.register( MetricRegistry.name(NotificationQueueDispatcher.class, "pending-notifications"), new Gauge<Integer>() { @Override public Integer getValue() { return pendingNotificationsQ.size(); } }); this.runners = new NotificationRunner[config.getNbThreads()]; for (int i = 0; i < config.getNbThreads(); i++) { runners[i] = new NotificationRunner(pendingNotificationsQ, clock, config, objectMapper, nbProcessedEvents, queues, dao, perQueueProcessingTime, metricRegistry, processedNotificationsSinceStart); } }
From source file:com.btoddb.fastpersitentqueue.JournalMgr.java
/** * * @throws IOException/*from ww w. ja v a 2 s .c o m*/ */ public void init() throws IOException { flushExec = new ScheduledThreadPoolExecutor(numberOfFlushWorkers, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread t = new Thread(runnable); t.setName("FPQ-FSync"); return t; } }); generalExec = Executors.newFixedThreadPool(numberOfGeneralWorkers, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread t = new Thread(runnable); t.setName("FPQ-GeneralWork"); return t; } }); prepareJournaling(); currentJournalDescriptor = createAndAddNewJournal(); }
From source file:com.google.devtools.build.lib.bazel.dash.DashModule.java
public DashModule() { // Make sure sender != null before we hop on the event bus. sender = NO_OP_SENDER;/*from w w w .jav a2 s . c o m*/ executorService = Executors.newFixedThreadPool(5, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setDaemon(true); return thread; } }); }
From source file:com.laudandjolynn.mytv.crawler.CrawlerGroup.java
@Override public List<TvStation> crawlAllTvStation() { List<TvStation> resultList = new ArrayList<TvStation>(); int size = crawlers.size(); int maxThreadNum = Constant.CPU_PROCESSOR_NUM; ThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("Mytv_CrawlerGroup_%d") .build();/*from ww w .j a v a 2s .co m*/ ExecutorService executorService = Executors.newFixedThreadPool(size > maxThreadNum ? maxThreadNum : size, threadFactory); CompletionService<List<TvStation>> completionService = new ExecutorCompletionService<List<TvStation>>( executorService); for (final Crawler crawler : crawlers) { Callable<List<TvStation>> task = new Callable<List<TvStation>>() { @Override public List<TvStation> call() throws Exception { return crawler.crawlAllTvStation(); } }; completionService.submit(task); } executorService.shutdown(); int count = 0; while (count < size) { try { List<TvStation> stationList = completionService.take().get(); if (stationList != null) { resultList.addAll(stationList); } } catch (InterruptedException e) { logger.error("crawl task of all tv station interrupted.", e); } catch (ExecutionException e) { logger.error("crawl task of all tv station executed fail.", e); } count++; } for (CrawlEventListener listener : listeners) { listener.crawlEnd(new AllTvStationCrawlEndEvent(this, resultList)); } return resultList; }
From source file:com.reactivetechnologies.platform.interceptor.AbstractOutboundChannel.java
@PostConstruct protected void init() { switch (strategy) { case PARALLEL_ORDERED: if (strategy.getComparator() != null) { Collections.sort(feeders, strategy.getComparator()); }// ww w . jav a2 s . c o m threads = Executors.newFixedThreadPool(strategy.getNoOfThreads(), new ThreadFactory() { int n = 0; @Override public Thread newThread(Runnable arg0) { Thread t = new Thread(arg0, "OutboundChannel-Worker-" + (n++)); return t; } }); parallel = true; break; case PARALLEL_RANDOM: threads = Executors.newFixedThreadPool(strategy.getNoOfThreads(), new ThreadFactory() { int n = 0; @Override public Thread newThread(Runnable arg0) { Thread t = new Thread(arg0, "OutboundChannel-Worker-" + (n++)); return t; } }); parallel = true; break; case SEQUENTIAL_ORDERED: if (strategy.getComparator() != null) { Collections.sort(feeders, strategy.getComparator()); } break; case SEQUENTIAL_RANDOM: break; default: break; } log.info("-- New Outbound channel created [" + name() + "]"); StringBuilder s = new StringBuilder(" { "); for (OutboundInterceptor<Serializable> out : feeders) { s.append("\n\t").append(out.name()).append(" - IN:").append(out.type()); } s.append("\n}"); log.info("[" + name() + "] Ready to outflow. No. of feeders " + feeders.size() + s); }
From source file:fr.dutra.confluence2wordpress.wp.WordpressClient.java
public WordpressClient(WordpressConnection wordpressConnection) { this.wordpressConnection = wordpressConnection; CommonsXmlRpcTransportFactory factory; URL url = wordpressConnection.getUrl(); if (this.wordpressConnection.getProxyHost() != null && this.wordpressConnection.getProxyPort() != null) { factory = new CommonsXmlRpcTransportFactory(url, wordpressConnection.getProxyHost(), wordpressConnection.getProxyPort(), wordpressConnection.getMaxConnections()); } else {//w w w . ja v a2 s. co m factory = new CommonsXmlRpcTransportFactory(url, wordpressConnection.getMaxConnections()); } this.client = new XmlRpcClient(url, factory); this.client.setMaxThreads(wordpressConnection.getMaxConnections()); this.pool = Executors.newFixedThreadPool(wordpressConnection.getMaxConnections(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("wp-client-%s").build()); }
From source file:net.kungfoo.grizzly.proxy.impl.ProxyAdapter.java
/** * {@inheritDoc}/*from w ww . jav a 2 s.c o m*/ */ public void service(Request request, Response response) throws Exception { String uri = request.unparsedURI().toString(); final MessageBytes method = request.method(); logURIAndMethod(uri, method); if (maxForwards(request, response, method)) return; String targetHost = request.serverName().toString(); int targetPort = request.getServerPort(); ProxyProcessingInfo proxyTask = new ProxyProcessingInfo(); // TODO: think of it. synchronized (proxyTask) { // from connected // Initialize connection state proxyTask.setTarget(new HttpHost(targetHost, targetPort)); proxyTask.setRequest(convert(method.getString(), uri, request)); proxyTask.setOriginalRequest(request); Runnable completion = (Runnable) request.getAttribute(CALLBACK_KEY); proxyTask.setCompletion(completion); proxyTask.setResponse(response); InetSocketAddress address = new InetSocketAddress(targetHost, targetPort); if (!IOReactorStatus.ACTIVE.equals(connectingIOReactor.getStatus())) { System.err.println("Connecting reactor not running."); response.setStatus(500); response.setMessage("Internal Booo"); // complete request. ExecutorService executorService = Executors.newFixedThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "EmergencyService"); //To change body of implemented methods use File | Settings | File Templates. } }); executorService.submit(completion); return; } else { connectingIOReactor.connect(address, null, proxyTask, null); } // from requestReceived try { System.out.println(request + " [client->proxy] >> " + request.unparsedURI().toString()); // Update connection state proxyTask.setClientState(ConnState.REQUEST_RECEIVED); if (request.getContentLength() != 0) { proxyTask.setClientState(ConnState.REQUEST_BODY_DONE); } // See if the client expects a 100-Continue if (isExpectContinue(request)) { response.setStatus(HttpStatus.SC_CONTINUE); response.sendHeaders(); } } catch (IOException ignore) { System.out.println("err " + ignore.getMessage()); } } // handle "Via", TODO: should go after we have headers from target server. response.setHeader(Via.name(), request.protocol() + " antares");// TODO hostname, and Via from response }