/** * Creates a daemon thread with the specified name prefix. Thread names will be namePrefix-<threadId>. Thread ID is * incremented each time a thread is created using this factory. * * @param namePrefix * not null. */ public NamedThreadFactory(String namePrefix) { this.namePrefix = Objects.requireNonNull(namePrefix); group = getThreadGroup(); daemon = true; }
public SpaceTaskDispatcher(GigaSpace gigaSpace, DynamicConfig config) { this.gigaSpace = gigaSpace; /* * TODO * (1) Improve configuration mechanism used to configure thread pool. */ String spaceInstanceName = gigaSpace.getName(); DynamicIntProperty poolSize = config.getIntProperty("astrix.beans.gigaspace." + spaceInstanceName + ".spaceTaskDispatcher.poolsize", 10); this.executorService = new ThreadPoolExecutor(poolSize.get(), poolSize.get(), 0, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory(String.format("SpaceTaskDispatcher[%s]", spaceInstanceName))); poolSize.addListener(newValue -> { log.info(String.format("Changing pool-size for SpaceTaskDistpatcher. space=%s newSize=%s, oldSize=%s", SpaceTaskDispatcher.this.gigaSpace.getName(), newValue, executorService.getMaximumPoolSize())); executorService.setCorePoolSize(newValue); executorService.setMaximumPoolSize(newValue); }); }