List of usage examples for java.util.concurrent ThreadPoolExecutor getMaximumPoolSize
public int getMaximumPoolSize()
From source file:com.l2jfree.util.concurrent.L2ThreadPool.java
private static long getMaximumPoolSize(ThreadPoolExecutor[] threadPools) { long result = 0; for (ThreadPoolExecutor threadPool : threadPools) result += threadPool.getMaximumPoolSize(); return result; }
From source file:Main.java
/** * //ww w . j av a 2s. com */ protected static void decorateProperties(ThreadPoolExecutor executor, Properties properties) { if (executor != null) { if (properties != null) { properties.setProperty("thread-keep-alive-time", Long.toString(executor.getKeepAliveTime(TimeUnit.MILLISECONDS))); properties.setProperty("thread-pool-size-largest", Integer.toString(executor.getLargestPoolSize())); properties.setProperty("thread-pool-size-minimum", Integer.toString(executor.getCorePoolSize())); properties.setProperty("thread-pool-size-maximum", Integer.toString(executor.getMaximumPoolSize())); properties.setProperty("thread-pool-size", Integer.toString(executor.getPoolSize())); properties.setProperty("runnable-completed-count", Long.toString(executor.getCompletedTaskCount())); properties.setProperty("runnable-active-count", Integer.toString(executor.getActiveCount())); properties.setProperty("queue-size", Integer.toString(executor.getQueue().size())); properties.setProperty("queue-capacity-remaining", Integer.toString(executor.getQueue().remainingCapacity())); } } }
From source file:fi.jumi.core.suite.SuiteFactoryTest.java
@Test public void test_thread_pool_uses_the_specified_number_of_threads() { daemon.setTestThreadsCount(3);/*www. j a v a 2 s . com*/ createSuiteFactory(); ThreadPoolExecutor testThreadPool = (ThreadPoolExecutor) factory.testThreadPool; assertThat(testThreadPool.getMaximumPoolSize(), is(3)); }
From source file:com.amazonaws.services.simpleworkflow.flow.worker.ActivityTaskPoller.java
public void setTaskExecutorService(ThreadPoolExecutor taskExecutorService) { this.taskExecutorService = taskExecutorService; pollSemaphore = new Semaphore(taskExecutorService.getMaximumPoolSize()); }
From source file:code.google.nfs.rpc.grizzly.server.GrizzlyServer.java
public void start(int listenPort, ExecutorService threadpool) throws Exception { ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) threadpool; ThreadPoolConfig config = ThreadPoolConfig.defaultConfig().copy() .setCorePoolSize(threadPoolExecutor.getCorePoolSize()) .setMaxPoolSize(threadPoolExecutor.getMaximumPoolSize()).setPoolName("GRIZZLY-SERVER"); ExecutorService executorService = GrizzlyExecutorService.createInstance(config); FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless(); filterChainBuilder.add(new TransportFilter()); filterChainBuilder.add(new GrizzlyProtocolFilter()); filterChainBuilder.add(new GrizzlyServerHandler(executorService)); TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance(); builder.setOptimizedForMultiplexing(true); builder.setIOStrategy(SameThreadIOStrategy.getInstance()); transport = builder.build();/*w w w.j a v a 2 s . com*/ transport.setProcessor(filterChainBuilder.build()); transport.bind(listenPort); transport.start(); LOGGER.warn("server started,listen at: " + listenPort); }
From source file:com.xerox.amazonws.sdb.Domain.java
/** * Gets attributes of given items. This method threads off the get requests and * aggregates the responses.//w ww . j a v a 2 s.com * * @param items the list of items to get attributes for * @param listener class that will be notified when items are ready * @throws SDBException wraps checked exceptions */ public void getItemsAttributes(List<String> items, ItemListener listener) throws SDBException { ThreadPoolExecutor pool = getThreadPoolExecutor(); pool.setRejectedExecutionHandler(new RejectionHandler()); Counter running = new Counter(0); for (String item : items) { while (pool.getActiveCount() == pool.getMaximumPoolSize()) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } synchronized (running) { running.increment(); } pool.execute(new AttrWorker(getItem(item), running, null, listener)); Thread.yield(); } while (true) { if (running.getValue() == 0) { break; } try { Thread.sleep(500); } catch (InterruptedException ex) { } } if (this.executor == null) { pool.shutdown(); } }
From source file:com.xerox.amazonws.sdb.Domain.java
/** * Gets attributes of given items. This method threads off the get requests and * aggregates the responses./* w ww. j a va2 s. c o m*/ * * @param items the list of items to get attributes for * @return the map of items with lists of attributes * @throws SDBException wraps checked exceptions */ public Map<String, List<ItemAttribute>> getItemsAttributes(List<String> items) throws SDBException { Map<String, List<ItemAttribute>> results = new Hashtable<String, List<ItemAttribute>>(); ThreadPoolExecutor pool = getThreadPoolExecutor(); pool.setRejectedExecutionHandler(new RejectionHandler()); Counter running = new Counter(0); for (String item : items) { while (pool.getActiveCount() == pool.getMaximumPoolSize()) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } synchronized (running) { running.increment(); } pool.execute(new AttrWorker(getItem(item), running, results, null)); Thread.yield(); } while (true) { if (running.getValue() == 0) { break; } try { Thread.sleep(500); } catch (InterruptedException ex) { } } if (this.executor == null) { pool.shutdown(); } return results; }
From source file:org.jmangos.commons.threadpool.CommonThreadPoolManager.java
/** * @see org.jmangos.commons.threadpool.ThreadPoolManager#fillPoolStats(org.jmangos.commons.threadpool.model.ThreadPoolType) */// w w w .java2 s . c o m @Override public PoolStats fillPoolStats(final ThreadPoolType poolType) { ThreadPoolExecutor executor = null; switch (poolType) { case INSTANT: executor = this.instantPool; break; case SCHEDULED: default: executor = this.scheduledPool; break; } final PoolStats stats = new PoolStats(poolType); stats.setActiveCount(executor.getActiveCount()); stats.setCompletedTaskCount(executor.getCompletedTaskCount()); stats.setCorePoolSize(executor.getCorePoolSize()); stats.setLargestPoolSize(executor.getLargestPoolSize()); stats.setMaximumPoolSize(executor.getMaximumPoolSize()); stats.setPoolSize(executor.getPoolSize()); stats.setQueueSize(executor.getQueue().size()); stats.setTaskCount(executor.getTaskCount()); return stats; }
From source file:com.xerox.amazonws.sdb.Domain.java
/** * Gets attributes of items specified in the query string. This method threads off the * get requests and aggregates the responses. * * @param queryString the filter statement * @param listener class that will be notified when items are ready * @throws SDBException wraps checked exceptions *///from ww w . j a v a 2s . co m public void listItemsAttributes(String queryString, ItemListener listener) throws SDBException { ThreadPoolExecutor pool = getThreadPoolExecutor(); pool.setRejectedExecutionHandler(new RejectionHandler()); String nextToken = ""; Counter running = new Counter(0); do { try { QueryResult result = listItems(queryString, nextToken, 250); List<Item> items = result.getItemList(); for (Item i : items) { while (pool.getActiveCount() == pool.getMaximumPoolSize()) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } synchronized (running) { running.increment(); } pool.execute(new AttrWorker(i, running, null, listener)); Thread.yield(); } nextToken = result.getNextToken(); } catch (SDBException ex) { System.out.println("Query '" + queryString + "' Failure: "); ex.printStackTrace(); } } while (nextToken != null && nextToken.trim().length() > 0); while (true) { if (running.getValue() == 0) { break; } try { Thread.sleep(500); } catch (InterruptedException ex) { } } if (this.executor == null) { pool.shutdown(); } }
From source file:org.apache.accumulo.tserver.TabletServer.java
@Override public void run() { SecurityUtil.serverLogin(SiteConfiguration.getInstance()); // To make things easier on users/devs, and to avoid creating an upgrade path to 1.7 // We can just make the zookeeper paths before we try to use. try {/* w w w . ja va 2 s. co m*/ ZooKeeperInitialization.ensureZooKeeperInitialized(ZooReaderWriter.getInstance(), ZooUtil.getRoot(getInstance())); } catch (KeeperException | InterruptedException e) { log.error("Could not ensure that ZooKeeper is properly initialized", e); throw new RuntimeException(e); } Metrics tserverMetrics = metricsFactory.createTabletServerMetrics(this); // Register MBeans try { tserverMetrics.register(); mincMetrics.register(); scanMetrics.register(); updateMetrics.register(); } catch (Exception e) { log.error("Error registering with JMX", e); } if (null != authKeyWatcher) { log.info("Seeding ZooKeeper watcher for authentication keys"); try { authKeyWatcher.updateAuthKeys(); } catch (KeeperException | InterruptedException e) { // TODO Does there need to be a better check? What are the error conditions that we'd fall out here? AUTH_FAILURE? // If we get the error, do we just put it on a timer and retry the exists(String, Watcher) call? log.error( "Failed to perform initial check for authentication tokens in ZooKeeper. Delegation token authentication will be unavailable.", e); } } try { clientAddress = startTabletClientService(); } catch (UnknownHostException e1) { throw new RuntimeException("Failed to start the tablet client service", e1); } announceExistence(); try { walMarker.initWalMarker(getTabletSession()); } catch (Exception e) { log.error("Unable to create WAL marker node in zookeeper", e); throw new RuntimeException(e); } ThreadPoolExecutor distWorkQThreadPool = new SimpleThreadPool( getConfiguration().getCount(Property.TSERV_WORKQ_THREADS), "distributed work queue"); bulkFailedCopyQ = new DistributedWorkQueue(ZooUtil.getRoot(getInstance()) + Constants.ZBULK_FAILED_COPYQ, getConfiguration()); try { bulkFailedCopyQ.startProcessing(new BulkFailedCopyProcessor(), distWorkQThreadPool); } catch (Exception e1) { throw new RuntimeException("Failed to start distributed work queue for copying ", e1); } try { logSorter.startWatchingForRecoveryLogs(distWorkQThreadPool); } catch (Exception ex) { log.error("Error setting watches for recoveries"); throw new RuntimeException(ex); } // Start the thrift service listening for incoming replication requests try { replicationAddress = startReplicationService(); } catch (UnknownHostException e) { throw new RuntimeException("Failed to start replication service", e); } // Start the pool to handle outgoing replications final ThreadPoolExecutor replicationThreadPool = new SimpleThreadPool( getConfiguration().getCount(Property.REPLICATION_WORKER_THREADS), "replication task"); replWorker.setExecutor(replicationThreadPool); replWorker.run(); // Check the configuration value for the size of the pool and, if changed, resize the pool, every 5 seconds); final AccumuloConfiguration aconf = getConfiguration(); Runnable replicationWorkThreadPoolResizer = new Runnable() { @Override public void run() { int maxPoolSize = aconf.getCount(Property.REPLICATION_WORKER_THREADS); if (replicationThreadPool.getMaximumPoolSize() != maxPoolSize) { log.info("Resizing thread pool for sending replication work from " + replicationThreadPool.getMaximumPoolSize() + " to " + maxPoolSize); replicationThreadPool.setMaximumPoolSize(maxPoolSize); } } }; SimpleTimer.getInstance(aconf).schedule(replicationWorkThreadPoolResizer, 10000, 30000); final long CLEANUP_BULK_LOADED_CACHE_MILLIS = 15 * 60 * 1000; SimpleTimer.getInstance(aconf).schedule(new BulkImportCacheCleaner(this), CLEANUP_BULK_LOADED_CACHE_MILLIS, CLEANUP_BULK_LOADED_CACHE_MILLIS); HostAndPort masterHost; while (!serverStopRequested) { // send all of the pending messages try { MasterMessage mm = null; MasterClientService.Client iface = null; try { // wait until a message is ready to send, or a sever stop // was requested while (mm == null && !serverStopRequested) { mm = masterMessages.poll(1000, TimeUnit.MILLISECONDS); } // have a message to send to the master, so grab a // connection masterHost = getMasterAddress(); iface = masterConnection(masterHost); TServiceClient client = iface; // if while loop does not execute at all and mm != null, // then finally block should place mm back on queue while (!serverStopRequested && mm != null && client != null && client.getOutputProtocol() != null && client.getOutputProtocol().getTransport() != null && client.getOutputProtocol().getTransport().isOpen()) { try { mm.send(rpcCreds(), getClientAddressString(), iface); mm = null; } catch (TException ex) { log.warn("Error sending message: queuing message again"); masterMessages.putFirst(mm); mm = null; throw ex; } // if any messages are immediately available grab em and // send them mm = masterMessages.poll(); } } finally { if (mm != null) { masterMessages.putFirst(mm); } returnMasterConnection(iface); sleepUninterruptibly(1, TimeUnit.SECONDS); } } catch (InterruptedException e) { log.info("Interrupt Exception received, shutting down"); serverStopRequested = true; } catch (Exception e) { // may have lost connection with master // loop back to the beginning and wait for a new one // this way we survive master failures log.error(getClientAddressString() + ": TServerInfo: Exception. Master down?", e); } } // wait for shutdown // if the main thread exits oldServer the master listener, the JVM will // kill the other threads and finalize objects. We want the shutdown that is // running in the master listener thread to complete oldServer this happens. // consider making other threads daemon threads so that objects don't // get prematurely finalized synchronized (this) { while (shutdownComplete == false) { try { this.wait(1000); } catch (InterruptedException e) { log.error(e.toString()); } } } log.debug("Stopping Replication Server"); TServerUtils.stopTServer(this.replServer); log.debug("Stopping Thrift Servers"); TServerUtils.stopTServer(server); try { log.debug("Closing filesystem"); fs.close(); } catch (IOException e) { log.warn("Failed to close filesystem : {}", e.getMessage(), e); } gcLogger.logGCInfo(getConfiguration()); log.info("TServerInfo: stop requested. exiting ... "); try { tabletServerLock.unlock(); } catch (Exception e) { log.warn("Failed to release tablet server lock", e); } }