@Override public void execute(Runnable command) { if (shutdown.get()) { throw new RejectedExecutionException(); } if (!taskQ.offer(command)) { throw new RejectedExecutionException("Executor[" + name + "] is overloaded!"); } addNewWorkerIfRequired(); }
@Override public <T> Future<T> submit(Runnable task, T result) { final RunnableFuture<T> rf = new CompletableFutureTask<T>(task, result, getAsyncExecutor()); execute(rf); return rf; }
@Override public Future<?> submit(Runnable task) { return submit(task, null); }
@SuppressFBWarnings("VO_VOLATILE_INCREMENT") private void addNewWorkerIfRequired() { if (size < maxPoolSize) { try { lock.lockInterruptibly(); try { if (size < maxPoolSize && getQueueSize() > 0) { size++; cachedExecutor.execute(new Worker()); } } finally { lock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
private ManagedExecutorService createExecutor(String name, int poolSize, int queueCapacity, ExecutorType type) { ManagedExecutorService executor; if (type == ExecutorType.CACHED) { executor = new CachedExecutorServiceDelegate(nodeEngine, name, cachedExecutorService, poolSize, queueCapacity); } else if (type == ExecutorType.CONCRETE) { ClassLoader classLoader = nodeEngine.getConfigClassLoader(); String hzName = nodeEngine.getHazelcastInstance().getName(); String internalName = name.startsWith("hz:") ? name.substring(BEGIN_INDEX) : name; String threadNamePrefix = createThreadPoolName(hzName, internalName); PoolExecutorThreadFactory threadFactory = new PoolExecutorThreadFactory(threadNamePrefix, classLoader); NamedThreadPoolExecutor pool = new NamedThreadPoolExecutor(name, poolSize, poolSize, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueCapacity), threadFactory ); pool.allowCoreThreadTimeOut(true); executor = pool; } else { throw new IllegalArgumentException("Unknown executor type: " + type); } return executor; }
@SuppressFBWarnings("VO_VOLATILE_INCREMENT") private void addNewWorkerIfRequired() { if (size < maxPoolSize) { try { lock.lockInterruptibly(); try { if (size < maxPoolSize && getQueueSize() > 0) { size++; cachedExecutor.execute(new Worker()); } } finally { lock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
private ManagedExecutorService createExecutor(String name, int poolSize, int queueCapacity, ExecutorType type) { ManagedExecutorService executor; if (type == ExecutorType.CACHED) { executor = new CachedExecutorServiceDelegate(nodeEngine, name, cachedExecutorService, poolSize, queueCapacity); } else if (type == ExecutorType.CONCRETE) { ClassLoader classLoader = nodeEngine.getConfigClassLoader(); String hzName = nodeEngine.getHazelcastInstance().getName(); String internalName = name.startsWith("hz:") ? name.substring(BEGIN_INDEX) : name; String threadNamePrefix = createThreadPoolName(hzName, internalName); PoolExecutorThreadFactory threadFactory = new PoolExecutorThreadFactory(threadNamePrefix, classLoader); NamedThreadPoolExecutor pool = new NamedThreadPoolExecutor(name, poolSize, poolSize, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueCapacity), threadFactory ); pool.allowCoreThreadTimeOut(true); executor = pool; } else { throw new IllegalArgumentException("Unknown executor type: " + type); } return executor; }
@Override public <T> Future<T> submit(Callable<T> task) { final RunnableFuture<T> rf = new CompletableFutureTask<T>(task, getAsyncExecutor()); execute(rf); return rf; }
@Override public void execute(Runnable command) { if (shutdown.get()) { throw new RejectedExecutionException(); } if (!taskQ.offer(command)) { throw new RejectedExecutionException("Executor[" + name + "] is overloaded!"); } addNewWorkerIfRequired(); }
@Override public Future<?> submit(Runnable task) { return submit(task, null); }
@Override public <T> Future<T> submit(Runnable task, T result) { final RunnableFuture<T> rf = new CompletableFutureTask<T>(task, result, getAsyncExecutor()); execute(rf); return rf; }
@Override public <T> Future<T> submit(Callable<T> task) { final RunnableFuture<T> rf = new CompletableFutureTask<T>(task, getAsyncExecutor()); execute(rf); return rf; }