List of usage examples for org.springframework.scheduling.concurrent CustomizableThreadFactory CustomizableThreadFactory
public CustomizableThreadFactory(String threadNamePrefix)
From source file:fr.xebia.springframework.concurrent.ThreadPoolExecutorFactory.java
@Override protected ThreadPoolExecutor createInstance() throws Exception { Assert.isTrue(this.corePoolSize >= 0, "corePoolSize must be greater than or equal to zero"); Assert.isTrue(this.maximumPoolSize > 0, "maximumPoolSize must be greater than zero"); Assert.isTrue(this.maximumPoolSize >= this.corePoolSize, "maximumPoolSize must be greater than or equal to corePoolSize"); Assert.isTrue(this.queueCapacity >= 0, "queueCapacity must be greater than or equal to zero"); CustomizableThreadFactory threadFactory = new CustomizableThreadFactory(this.beanName + "-"); threadFactory.setDaemon(true);//from w ww . j a va2s .c o m BlockingQueue<Runnable> blockingQueue; if (queueCapacity == 0) { blockingQueue = new SynchronousQueue<Runnable>(); } else { blockingQueue = new LinkedBlockingQueue<Runnable>(queueCapacity); } ThreadPoolExecutor instance = new SpringJmxEnabledThreadPoolExecutor(corePoolSize, // maximumPoolSize, // keepAliveTimeInSeconds, // TimeUnit.SECONDS, // blockingQueue, // threadFactory, // rejectedExecutionHandlerClass.newInstance(), // new ObjectName("java.util.concurrent:type=ThreadPoolExecutor,name=" + beanName)); return instance; }
From source file:org.geowebcache.diskquota.DiskQuotaMonitor.java
private ScheduledExecutorService createCleanUpExecutor() { final int numCleaningThreads = quotaConfig.getMaxConcurrentCleanUps(); log.info("Setting up disk quota periodic enforcement task"); CustomizableThreadFactory tf = new CustomizableThreadFactory("GWC DiskQuota clean up thread-"); tf.setThreadPriority(1 + (Thread.MAX_PRIORITY - Thread.MIN_PRIORITY) / 5); ScheduledExecutorService executorService = Executors.newScheduledThreadPool(numCleaningThreads, tf); return executorService; }
From source file:org.alfresco.bm.server.EventController.java
/** * Construct the controller// w ww .ja v a 2s.com * * @param driverId the ID of the driver controlling the events * @param testRunFqn the fully qualified name of the test run * @param testDAO the test DAO for accessing low level data * @param testRunId the ID of the test run being controlled * @param eventService the source of events that will be pushed for execution * @param eventProducers the registry of producers of events * @param eventProcessors the registry of processors for events * @param resultService the service used to store and retrieve event results * @param sessionService the service to carry session IDs between events * @param logService the service to record log messages for the end user * @param threadCount the number of threads available to the processor */ public EventController(String driverId, String testRunFqn, EventService eventService, EventProducerRegistry eventProducers, EventProcessorRegistry eventProcessors, ResultService resultService, SessionService sessionService, TestRunLogService logService, int threadCount) { thread = new Thread(new ThreadGroup(testRunFqn), this, testRunFqn + "-Controller"); thread.setDaemon(false); // Requires explicit shutdown this.driverId = driverId; this.testRunFqn = testRunFqn; this.eventService = eventService; this.eventProducers = eventProducers; this.eventProcessors = eventProcessors; this.resultService = resultService; this.sessionService = sessionService; this.logService = logService; this.threadCount = threadCount; // Configure threads CustomizableThreadFactory threadFactory = new CustomizableThreadFactory(testRunFqn + "-"); threadFactory.setThreadGroup(thread.getThreadGroup()); threadFactory.setDaemon(true); // Configure work queue SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>(true); // Configure executor RejectedExecutionHandler abortPolicy = new ThreadPoolExecutor.CallerRunsPolicy(); executor = new ThreadPoolExecutor(threadCount, threadCount, 60, TimeUnit.SECONDS, queue, threadFactory, abortPolicy); setRunning(true); }
From source file:org.cloudfoundry.receptor.events.EventDispatcher.java
public EventDispatcher(String url, RestOperations restTemplate) { Assert.hasText(url, "URL is required"); Assert.notNull(restTemplate, "RestTemplate is required"); this.url = url; this.restTemplate = restTemplate; this.backgroundExecutor = Executors .newSingleThreadExecutor(new CustomizableThreadFactory("receptor-event-subscriber-")); this.dispatchingExecutor = Executors .newCachedThreadPool(new CustomizableThreadFactory("receptor-event-dispatcher-")); }
From source file:org.geowebcache.diskquota.bdb.BDBQuotaStore.java
/** * @throws InterruptedException//from ww w .j ava 2 s. co m * @see {@link #close()} */ public void startUp() throws InterruptedException, IOException { if (!diskQuotaEnabled) { log.info(getClass().getName() + " won't start, got env variable " + GWC_DISKQUOTA_DISABLED + "=true"); return; } open = true; File storeDirectory = new File(cacheRootDir, "diskquota_page_store"); storeDirectory.mkdirs(); File version = new File(storeDirectory, VERSION_FILE); if (storeDirectory.list().length == 0) { // Directory is empty try { FileUtils.write(version, STORE_VERSION); } catch (IOException e) { throw new IOException("BDB DiskQuota could not write " + VERSION_FILE + " to new database", e); } } else { // Directory not empty try { String versionString = FileUtils.readFileToString(version); if (!versionString.equals(STORE_VERSION)) { throw new IOException("BDB DiskQuota does not support database version " + versionString); } } catch (IOException e) { throw new IOException( "BDB DiskQuota could not read " + VERSION_FILE + " to detemine database version", e); } } CustomizableThreadFactory tf = new CustomizableThreadFactory("GWC DiskQuota Store Writer-"); transactionRunner = Executors.newFixedThreadPool(1, tf); try { configure(storeDirectory); deleteStaleLayersAndCreateMissingTileSets(); log.info("Berkeley DB JE Disk Quota page store configured at " + storeDirectory.getAbsolutePath()); } catch (RuntimeException e) { transactionRunner.shutdownNow(); throw e; } log.info("Quota Store initialized. Global quota: " + getGloballyUsedQuota().toNiceString()); }
From source file:org.springframework.amqp.rabbit.connection.AbstractConnectionFactoryTests.java
@Test public void testCreatesConnectionWithGivenFactory() throws Exception { com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock( com.rabbitmq.client.ConnectionFactory.class); doCallRealMethod().when(mockConnectionFactory).params(any(ExecutorService.class)); doCallRealMethod().when(mockConnectionFactory).setThreadFactory(any(ThreadFactory.class)); doCallRealMethod().when(mockConnectionFactory).getThreadFactory(); AbstractConnectionFactory connectionFactory = createConnectionFactory(mockConnectionFactory); ThreadFactory connectionThreadFactory = new CustomizableThreadFactory("connection-thread-"); connectionFactory.setConnectionThreadFactory(connectionThreadFactory); assertEquals(connectionThreadFactory, mockConnectionFactory.getThreadFactory()); }