List of usage examples for java.util.concurrent ThreadPoolExecutor ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
From source file:org.apache.hadoop.hbase.regionserver.CompactSplit.java
/** @param server */ CompactSplit(HRegionServer server) {/*from ww w. ja v a 2 s . c om*/ super(); this.server = server; this.conf = server.getConfiguration(); this.regionSplitLimit = conf.getInt(REGION_SERVER_REGION_SPLIT_LIMIT, DEFAULT_REGION_SERVER_REGION_SPLIT_LIMIT); int largeThreads = Math.max(1, conf.getInt(LARGE_COMPACTION_THREADS, LARGE_COMPACTION_THREADS_DEFAULT)); int smallThreads = conf.getInt(SMALL_COMPACTION_THREADS, SMALL_COMPACTION_THREADS_DEFAULT); int splitThreads = conf.getInt(SPLIT_THREADS, SPLIT_THREADS_DEFAULT); // if we have throttle threads, make sure the user also specified size Preconditions.checkArgument(largeThreads > 0 && smallThreads > 0); final String n = Thread.currentThread().getName(); StealJobQueue<Runnable> stealJobQueue = new StealJobQueue<>(); this.longCompactions = new ThreadPoolExecutor(largeThreads, largeThreads, 60, TimeUnit.SECONDS, stealJobQueue, new ThreadFactory() { @Override public Thread newThread(Runnable r) { String name = n + "-longCompactions-" + System.currentTimeMillis(); return new Thread(r, name); } }); this.longCompactions.setRejectedExecutionHandler(new Rejection()); this.longCompactions.prestartAllCoreThreads(); this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60, TimeUnit.SECONDS, stealJobQueue.getStealFromQueue(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { String name = n + "-shortCompactions-" + System.currentTimeMillis(); return new Thread(r, name); } }); this.shortCompactions.setRejectedExecutionHandler(new Rejection()); this.splits = (ThreadPoolExecutor) Executors.newFixedThreadPool(splitThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { String name = n + "-splits-" + System.currentTimeMillis(); return new Thread(r, name); } }); int mergeThreads = conf.getInt(MERGE_THREADS, MERGE_THREADS_DEFAULT); this.mergePool = (ThreadPoolExecutor) Executors.newFixedThreadPool(mergeThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { String name = n + "-merges-" + System.currentTimeMillis(); return new Thread(r, name); } }); // compaction throughput controller this.compactionThroughputController = CompactionThroughputControllerFactory.create(server, conf); }
From source file:com.nextgis.maplib.display.TMSRenderer.java
@Override public void runDraw(final GISDisplay display) throws NullPointerException { final double zoom = display.getZoomLevel(); GeoEnvelope env = display.getBounds(); //get tiled for zoom and bounds final TMSLayer tmsLayer = (TMSLayer) mLayer; final List<TileItem> tiles = tmsLayer.getTielsForBounds(display, env, zoom); int threadCount = tmsLayer.getMaxThreadCount(); if (threadCount > 0) mDrawThreadPool = new ThreadPoolExecutor(threadCount, threadCount, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, new LinkedBlockingQueue<Runnable>(), new RejectedExecutionHandler() { @Override/* w w w . jav a 2 s . co m*/ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { executor.getQueue().put(r); } catch (InterruptedException e) { e.printStackTrace(); //throw new RuntimeException("Interrupted while submitting task", e); } } }); if (null == mDrawThreadPool) { tmsLayer.onDrawFinished(tmsLayer.getId(), 1); return; } if (tiles.size() == 0) { tmsLayer.onDrawFinished(tmsLayer.getId(), 1); return; } for (int i = 0; i < tiles.size(); ++i) { final TileItem tile = tiles.get(i); mDrawThreadPool.execute(new Runnable() { @Override public void run() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); final Bitmap bmp = tmsLayer.getBitmap(tile); if (bmp != null) { display.drawTile(bmp, tile.getPoint(), mRasterPaint); } float percent = 1; synchronized (mLayer) { if (mDrawThreadPool.getTaskCount() > 1) percent = (float) (mDrawThreadPool.getCompletedTaskCount() + 1) / mDrawThreadPool.getTaskCount(); tmsLayer.onDrawFinished(tmsLayer.getId(), percent); } //Log.d(TAG, "percent: " + percent + " complete: " + mDrawThreadPool.getCompletedTaskCount() + " task count: " + mDrawThreadPool.getTaskCount()); } }); } }
From source file:org.apache.hadoop.hbase.thrift.TBoundedThreadPoolServer.java
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) { super(options); if (options.maxQueuedRequests > 0) { this.callQueue = new CallQueue(new LinkedBlockingQueue<Call>(options.maxQueuedRequests), metrics); } else {/*from w w w.j ava2s. co m*/ this.callQueue = new CallQueue(new SynchronousQueue<Call>(), metrics); } ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setDaemon(true); tfb.setNameFormat("thrift-worker-%d"); executorService = new ThreadPoolExecutor(options.minWorkerThreads, options.maxWorkerThreads, options.threadKeepAliveTimeSec, TimeUnit.SECONDS, this.callQueue, tfb.build()); serverOptions = options; }
From source file:org.apache.streams.twitter.provider.TwitterUserInformationProvider.java
public static ExecutorService newFixedThreadPoolWithQueueSize(int numThreads, int queueSize) { return new ThreadPoolExecutor(numThreads, numThreads, 5000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:org.github.gitswarm.GitSwarm.java
/** * Initialization//from w w w .ja v a 2 s. c o m */ @Override public void setup() { int maxBackgroundThreads = 4; backgroundExecutor = new ThreadPoolExecutor(1, maxBackgroundThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new ArrayBlockingQueue<>(4 * maxBackgroundThreads), new ThreadPoolExecutor.CallerRunsPolicy()); showDebug = false; background = ColorUtil.toAwtColor(Config.getInstance().getBackground().getValue()).getRGB(); fontColor = ColorUtil.toAwtColor(Config.getInstance().getFontColor().getValue()).getRGB(); double framesperday = Config.getInstance().getFramesPerDay(); UPDATE_DELTA = (long) (86400000 / framesperday); smooth(); frameRate(24); // init data structures nodes = new HashMap<>(); edges = new HashMap<>(); people = new HashMap<>(); history = new LinkedList<>(); loadRepEvents(); if (commits.isEmpty()) { return; } prevDate = commits.get(0).getDate(); maxFramesSaved = (int) Math.pow(10, Config.getInstance().getScreenshotFileMask().getValue().replaceAll("[^#]", "").length()); // Create fonts String fontName = Config.getInstance().getFont(); String boldFontName = Config.getInstance().getBoldFont(); Integer fontSize = Config.getInstance().getFontSize().getValue(); Integer fontSizeBold = Config.getInstance().getBoldFontSize().getValue(); font = createFont(fontName, fontSize); boldFont = createFont(boldFontName, fontSizeBold); textFont(font); // Create the file particle image sprite = loadImage("src/main/resources/particle.png"); avatarMask = loadImage("src/main/resources/mask.png"); avatarMask.resize(40, 40); // Add translucency (using itself in this case) sprite.mask(sprite); }
From source file:org.flowable.job.service.impl.asyncexecutor.DefaultAsyncJobExecutor.java
protected void initAsyncJobExecutionThreadPool() { if (threadPoolQueue == null) { LOGGER.info("Creating thread pool queue of size {}", queueSize); threadPoolQueue = new ArrayBlockingQueue<>(queueSize); }// www . j a v a2 s . c o m if (executorService == null) { LOGGER.info("Creating executor service with corePoolSize {}, maxPoolSize {} and keepAliveTime {}", corePoolSize, maxPoolSize, keepAliveTime); BasicThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern("flowable-async-job-executor-thread-%d").build(); executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, threadPoolQueue, threadFactory); } }
From source file:org.rhq.core.pc.inventory.ResourceFactoryManager.java
public void initialize() { log.info("Initializing"); // Retrieve handle to metadata manager metadataManager = PluginContainer.getInstance().getPluginManager().getMetadataManager(); // Initialize thread pool for executing tasks int corePoolSize = configuration.getResourceFactoryCoreThreadPoolSize(); int keepAliveTime = configuration.getResourceFactoryKeepAliveTime(); int maxPoolSize = configuration.getResourceFactoryMaxThreadPoolSize(); executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(10000), new LoggingThreadFactory("ResourceFactory.executor", true)); }
From source file:org.rhq.core.pc.content.ContentManager.java
public void initialize() { log.info("Initializing Content Manager..."); // Determine discovery mode - we only enable discovery if we are inside the agent and the period is positive non-zero this.scheduledDiscoveriesEnabled = (configuration.getContentDiscoveryPeriod() > 0); // Create thread pool executor. Used in both scheduled and non-scheduled mode for all discoveries. int threadPoolSize = configuration.getContentDiscoveryThreadPoolSize(); discoveryThreadPoolExecutor = new ScheduledThreadPoolExecutor(threadPoolSize, new LoggingThreadFactory("Content.discovery", true)); discoveryThreadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); discoveryThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); crudExecutor = new ThreadPoolExecutor(1, 5, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10000), new LoggingThreadFactory("Content.crud", true)); // When running in scheduled mode, create and schedule the thread pool for discovering content if (scheduledDiscoveriesEnabled) { log.info("Initializing scheduled content discovery..."); // Without specifying a particular piece of work, this runner will request the next piece of work from // the scheduled items queue ContentDiscoveryRunner runner = new ContentDiscoveryRunner(this); // Begin the automatic discovery thread long initialDelay = configuration.getContentDiscoveryInitialDelay(); long discoveryPeriod = configuration.getContentDiscoveryPeriod(); discoveryThreadPoolExecutor.scheduleAtFixedRate(runner, initialDelay, discoveryPeriod, TimeUnit.SECONDS); // Add inventory event listener so we can keep the scheduled discoveries consistent with the resources inventoryEventListener = new ContentInventoryEventListener(); // the inventory manager has probably already activated some resources, so let's prepopulate our schedules InventoryManager im = PluginContainer.getInstance().getInventoryManager(); im.notifyForAllActivatedResources(inventoryEventListener); // now ask that the inventory manager tell us about resources that will be activated in the future im.addInventoryEventListener(inventoryEventListener); }//from w ww. j a va2s. c o m log.info("Content Manager initialized..."); }
From source file:com.googlecode.jmxtrans.guice.JmxTransModule.java
private ThreadPoolExecutor createExecutorService(int poolSize, int workQueueCapacity, String componentName) { BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(workQueueCapacity); ThreadFactory threadFactory = threadFactory(componentName); return new ThreadPoolExecutor(poolSize, poolSize, 0L, MILLISECONDS, workQueue, threadFactory); }
From source file:it.drwolf.ridire.session.async.JobMapperMonitor.java
private void create() { int transactionTimeoutSeconds = 240; try {//from w w w . j a v a 2 s.c o m ((javax.transaction.UserTransaction) org.jboss.seam.transaction.Transaction.instance()) .setTransactionTimeout(transactionTimeoutSeconds); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 8443)); this.httpClient = new HttpClient(); this.httpClient.getParams().setAuthenticationPreemptive(true); this.mainUserTx = (UserTransaction) org.jboss.seam.Component .getInstance("org.jboss.seam.transaction.transaction", ScopeType.APPLICATION); Credentials defaultcreds = null; int jobsToBeProcessed = 4; try { this.mainUserTx.setTransactionTimeout(10 * 10 * 60); // 10 mins this.mainUserTx.begin(); this.eventEntityManager.joinTransaction(); defaultcreds = new UsernamePasswordCredentials("admin", this.eventEntityManager .find(CommandParameter.class, CommandParameter.HERITRIX_ADMINPW_KEY).getCommandValue()); jobsToBeProcessed = Integer.parseInt(this.eventEntityManager .find(Parameter.class, Parameter.JOBS_TO_BE_PROCESSED.getKey()).getValue()); JobMapperMonitor.JOBSDIR = this.eventEntityManager.find(Parameter.class, Parameter.JOBS_DIR.getKey()) .getValue(); this.flagBearer.setHostname( this.eventEntityManager.find(Parameter.class, Parameter.HOSTNAME.getKey()).getValue()); this.eventEntityManager.flush(); this.mainUserTx.commit(); } catch (Exception e) { e.printStackTrace(); } this.httpClient.getState().setCredentials( new AuthScope(AuthScope.ANY_SCHEME, AuthScope.ANY_PORT, AuthScope.ANY_REALM), defaultcreds); Logger httpClientlogger = Logger.getLogger(this.httpClient.getClass()); httpClientlogger.setLevel(Level.ERROR); Logger authChallengeProcessorLogger = Logger.getLogger(AuthChallengeProcessor.class); authChallengeProcessorLogger.setLevel(Level.ERROR); Logger httpMethodBaseLogger = Logger.getLogger(HttpMethodBase.class); httpMethodBaseLogger.setLevel(Level.ERROR); this.highPoolThreadFactory = new PoolThreadFactory(JobMapperMonitor.THREADS_PRIORITY); this.threadPool = new ThreadPoolExecutor(jobsToBeProcessed, jobsToBeProcessed, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), this.highPoolThreadFactory); }