List of usage examples for java.util.concurrent Executors newScheduledThreadPool
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory)
From source file:io.mandrel.worker.WorkerContainer.java
public WorkerContainer(ExtractorService extractorService, Accumulators accumulators, Spider spider, Clients clients, DiscoveryClient discoveryClient) { super(accumulators, spider, clients); context.setDefinition(spider);//from w ww . ja va 2s . co m this.extractorService = extractorService; // Create the thread factory BasicThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern("worker-" + spider.getId() + "-%d").daemon(true).priority(Thread.MAX_PRIORITY) .build(); // Get number of parallel loops int parallel = Runtime.getRuntime().availableProcessors(); // Prepare a pool for the X parallel loops and the barrier refresh executor = Executors.newScheduledThreadPool(parallel + 1, threadFactory); // Prepare the barrier Barrier barrier = new Barrier(spider.getFrontier().getPoliteness(), discoveryClient); executor.scheduleAtFixedRate(() -> barrier.updateBuckets(), 10, 10, TimeUnit.SECONDS); // Create loop loops = new ArrayList<>(parallel); IntStream.range(0, parallel).forEach(idx -> { Loop loop = new Loop(extractorService, spider, clients, accumulators.spiderAccumulator(spider.getId()), accumulators.globalAccumulator(), barrier); loops.add(loop); executor.submit(loop); }); // Init stores MetadataStore metadatastore = spider.getStores().getMetadataStore().build(context); metadatastore.init(); MetadataStores.add(spider.getId(), metadatastore); BlobStore blobStore = spider.getStores().getBlobStore().build(context); blobStore.init(); BlobStores.add(spider.getId(), blobStore); if (spider.getExtractors().getData() != null) { spider.getExtractors().getData().forEach(ex -> { DocumentStore documentStore = ex.getDocumentStore().metadataExtractor(ex).build(context); documentStore.init(); DocumentStores.add(spider.getId(), ex.getName(), documentStore); }); } // Init requesters spider.getClient().getRequesters().forEach(r -> { Requester<?> requester = r.build(context); // Prepare client if (requester.strategy().nameResolver() != null) { requester.strategy().nameResolver().init(); } if (requester.strategy().proxyServersSource() != null) { requester.strategy().proxyServersSource().init(); } requester.init(); Requesters.add(spider.getId(), requester); }); current.set(ContainerStatus.INITIATED); }
From source file:com.aol.advertising.qiao.util.CommonUtils.java
public static ScheduledExecutorService createScheduledExecutorService(final int poolSz, final String threadName) { return Executors.newScheduledThreadPool(poolSz, new ThreadFactory() { private AtomicInteger threadNum = new AtomicInteger(0); @Override/*from ww w .jav a 2s .c om*/ public Thread newThread(Runnable r) { if (poolSz == 1) return new Thread(r, threadName); else return new Thread(r, threadName + threadNum.incrementAndGet()); } }); }
From source file:org.apache.hadoop.yarn.server.sharedcachemanager.CleanerService.java
@Override protected void serviceInit(Configuration conf) throws Exception { this.conf = conf; // create scheduler executor service that services the cleaner tasks // use 2 threads to accommodate the on-demand tasks and reduce the chance of // back-to-back runs ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("Shared cache cleaner").build(); scheduledExecutor = Executors.newScheduledThreadPool(2, tf); super.serviceInit(conf); }
From source file:org.wso2.carbon.databridge.agent.endpoint.DataEndpointGroup.java
public DataEndpointGroup(HAType haType, DataEndpointAgent agent) { this.dataEndpoints = new ArrayList<>(); this.haType = haType; this.reconnectionService = Executors.newScheduledThreadPool(1, new DataBridgeThreadFactory("ReconnectionService")); this.reconnectionInterval = agent.getAgentConfiguration().getReconnectionInterval(); this.publishingStrategy = agent.getAgentConfiguration().getPublishingStrategy(); if (!publishingStrategy.equalsIgnoreCase(DataEndpointConstants.SYNC_STRATEGY)) { this.eventQueue = new EventQueue(agent.getAgentConfiguration().getQueueSize()); }/* w ww. ja v a 2 s .c o m*/ this.reconnectionService.scheduleAtFixedRate(new ReconnectionTask(), reconnectionInterval, reconnectionInterval, TimeUnit.SECONDS); currentDataPublisherIndex.set(START_INDEX); }
From source file:org.wso2.andes.server.cluster.ClusterManager.java
/** * Initialize the Cluster manager./*w w w . j a va 2s. co m*/ * * @throws AndesException */ public void init() throws AndesException { if (AndesContext.getInstance().isClusteringEnabled()) { initClusterMode(); ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("SlotRecoveryOneTimeTask-%d").build(); slotRecoveryTaskService = Executors.newScheduledThreadPool(SLOT_SUBMIT_TASK_POOL_SIZE, namedThreadFactory); } else { initStandaloneMode(); } // set storeOperational to true since it can be assumed that the store is operational at startup // if it is non-operational, the value will be updated immediately storeOperational = true; // Register this instance to listen to the store health FailureObservingStoreManager.registerStoreHealthListener(this); }
From source file:org.apache.pulsar.functions.worker.WorkerService.java
public WorkerService(WorkerConfig workerConfig) { this.workerConfig = workerConfig; this.statsUpdater = Executors .newSingleThreadScheduledExecutor(new DefaultThreadFactory("worker-stats-updater")); this.executor = Executors.newScheduledThreadPool(10, new DefaultThreadFactory("pulsar-worker")); this.metricsGenerator = new MetricsGenerator(this.statsUpdater, workerConfig); }
From source file:org.commonreality.participant.impl.AbstractParticipant.java
/** * return a shared periodic executor that can be useful in many circumstances * for periodic events/*from w w w. ja v a 2 s .co m*/ * * @return */ static public ScheduledExecutorService getPeriodicExecutor() { synchronized (AbstractParticipant.class) { if (_periodicExecutor == null || _periodicExecutor.isShutdown() || _periodicExecutor.isTerminated()) _periodicExecutor = Executors.newScheduledThreadPool(1, new GeneralThreadFactory("IParticipant-Periodic")); return _periodicExecutor; } }
From source file:com.geekcap.javaworld.sparkexample.proxy.CustomClientBuilder.java
public CustomClientBuilder() { enableGZip = true;/* w ww .ja v a2 s . com*/ name = "hosebird-client-" + clientNum.getAndIncrement(); ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("hosebird-client-io-thread-%d").build(); executorService = Executors.newSingleThreadExecutor(threadFactory); ThreadFactory rateTrackerThreadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("hosebird-client-rateTracker-thread-%d").build(); ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1, rateTrackerThreadFactory); rateTracker = new BasicRateTracker(30000, 100, true, scheduledExecutor); reconnectionManager = new BasicReconnectionManager(5); socketTimeoutMillis = 60000; connectionTimeoutMillis = 4000; schemeRegistry = SchemeRegistryFactory.createDefault(); }
From source file:org.apache.hadoop.hbase.regionserver.MemStoreChunkPool.java
MemStoreChunkPool(Configuration conf, int chunkSize, int maxCount, int initialCount) { this.maxCount = maxCount; this.chunkSize = chunkSize; this.reclaimedChunks = new LinkedBlockingQueue<Chunk>(); for (int i = 0; i < initialCount; i++) { Chunk chunk = new Chunk(chunkSize); chunk.init();/* w ww . j a va 2 s .co m*/ reclaimedChunks.add(chunk); } final String n = Thread.currentThread().getName(); scheduleThreadPool = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder() .setNameFormat(n + "-MemStoreChunkPool Statistics").setDaemon(true).build()); this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this), statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS); }
From source file:edu.umass.cs.nio.JSONMessenger.java
/** * @param niot/*from w ww. j a v a 2s .co m*/ * @param numWorkers */ @SuppressWarnings("unchecked") public JSONMessenger(final InterfaceNIOTransport<NodeIDType, JSONObject> niot, int numWorkers) { // to not create thread pools unnecessarily if (niot instanceof JSONMessenger) this.execpool = ((JSONMessenger<NodeIDType>) niot).execpool; else this.execpool = Executors.newScheduledThreadPool(5, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setName(JSONMessenger.class.getSimpleName() + niot.getMyID() + thread.getName()); return thread; } }); nioTransport = (InterfaceNIOTransport<NodeIDType, JSONObject>) niot; this.workers = new MessageNIOTransport[numWorkers]; for (int i = 0; i < workers.length; i++) { try { log.info((this + " starting worker with ssl mode " + this.nioTransport.getSSLMode())); this.workers[i] = new MessageNIOTransport<NodeIDType, JSONObject>(null, this.getNodeConfig(), this.nioTransport.getSSLMode()); this.workers[i].setName(JSONMessenger.class.getSimpleName() + niot.getMyID() + "_send_worker" + i); } catch (IOException e) { this.workers[i] = null; e.printStackTrace(); } } }