Refine search
public synchronized ExecutorService executorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { // waiting for a thread to pick up instead of throwing exceptions. queue.put(r); } catch (InterruptedException e) { throw new RejectedExecutionException(e); } } });
@Override public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException { // try to empty the task queue Runnable task; if (threadSafeQueue) { task = taskQueue.poll(); } else { synchronized (taskQueue) { task = taskQueue.poll(); } } if (task != null) { return task; } // block and wait for a task to be submitted return super.poll(timeout, unit); } }
private ThreadPoolExecutor createExecutor() { ThreadPoolExecutor exec = new ThreadPoolExecutor(0, Integer.MAX_VALUE, getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory); exec.allowCoreThreadTimeOut(true); return exec; }
protected ThreadPoolExecutor createThreadPool() { ThreadPoolExecutor threadPool=new ThreadPoolExecutor(0, max_pool, pool_thread_keep_alive, TimeUnit.MILLISECONDS, new SynchronousQueue<>()); ThreadFactory factory=new ThreadFactory() { private final AtomicInteger thread_id=new AtomicInteger(1); public Thread newThread(final Runnable command) { return getThreadFactory().newThread(command, "StreamingStateTransfer-sender-" + thread_id.getAndIncrement()); } }; threadPool.setRejectedExecutionHandler(new ShutdownRejectedExecutionHandler(threadPool.getRejectedExecutionHandler())); threadPool.setThreadFactory(factory); return threadPool; }
/** * Create the BlockingQueue to use for the ThreadPoolExecutor. * <p>A LinkedBlockingQueue instance will be created for a positive * capacity value; a SynchronousQueue else. * @param queueCapacity the specified queue capacity * @return the BlockingQueue instance * @see java.util.concurrent.LinkedBlockingQueue * @see java.util.concurrent.SynchronousQueue */ protected BlockingQueue<Runnable> createQueue(int queueCapacity) { if (queueCapacity > 0) { return new LinkedBlockingQueue<>(queueCapacity); } else { return new SynchronousQueue<>(); } }
if(slopQueue == null) { slopQueue = new SynchronousQueue<Versioned<Slop>>(); slopQueues.put(nodeId, slopQueue); consumerResults.add(consumerExecutor.submit(new SlopConsumer(nodeId, slopStorageEngine))); boolean offered = slopQueue.offer(versioned, voldemortConfig.getClientRoutingTimeoutMs(), TimeUnit.MILLISECONDS); slopQueue.put(END); } catch(InterruptedException e) { logger.warn("Error putting poison pill", e);
@Override public void intercept(final IMethodInvocation invocation) throws Throwable { final Thread mainThread = Thread.currentThread(); final SynchronousQueue<StackTraceElement[]> sync = new SynchronousQueue<>(); final CountDownLatch startLatch = new CountDownLatch(2); while (stackTrace == null) { try { stackTrace = sync.take(); } catch (InterruptedException e) {
RateLimiter.Metrics detailedMetrics = limit.getMetrics(); SynchronousQueue<Object> synchronousQueue = new SynchronousQueue<>(); Thread thread = new Thread(() -> { run(() -> { for (int i = 0; i < LIMIT; i++) { synchronousQueue.put(O); limit.getPermission(TIMEOUT); synchronousQueue.take();
final SynchronousQueue<KeyValue<String, GenericRow>> rowQueue = new SynchronousQueue<>(); writtenRows.add(value); rowQueue.put(new KeyValue<>(key, value));
@Test public void subscription() throws Exception { TestApplicationContext context = TestUtils.createTestApplicationContext(); SynchronousQueue<String> queue = new SynchronousQueue<>(); TestBean testBean = new TestBean(queue); QueueChannel channel = new QueueChannel(); context.registerChannel("channel", channel); Message<String> message = new GenericMessage<>("testing"); channel.send(message); assertNull(queue.poll()); MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo"); handler.setBeanFactory(context); PollingConsumer endpoint = new PollingConsumer(channel, handler); endpoint.setTrigger(new PeriodicTrigger(10)); context.registerEndpoint("testEndpoint", endpoint); context.refresh(); String result = queue.poll(2000, TimeUnit.MILLISECONDS); assertNotNull(result); assertEquals("testing", result); context.close(); }
/** * Process task. * * @param task the task to be processed * @throws InterruptedException when thread has been interrupted */ public void process(WebcamTask task) throws InterruptedException { inbound.put(task); Throwable t = outbound.take().getThrowable(); if (t != null) { throw new WebcamException("Cannot execute task", t); } }
@Override public Runnable take() throws InterruptedException { // try to empty the task queue Runnable task; if (threadSafeQueue) { task = taskQueue.poll(); } else { synchronized (taskQueue) { task = taskQueue.poll(); } } if (task != null) { return task; } // block and wait for a task to be submitted return super.take(); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final String urlWithIdAndToken = exchange.getRequestURL() + "?" + exchange.getQueryString(); logger.log(Level.INFO, "Got a request to " + urlWithIdAndToken); queue.add(urlWithIdAndToken); TimeUnit.SECONDS.sleep(2); final OAuthWebResponse oauthWebResponse = (OAuthWebResponse) queue.take(); logger.log(Level.INFO, "Got an oauth response with code " + oauthWebResponse.getCode()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); exchange.setResponseCode(oauthWebResponse.getCode()); exchange.getResponseSender().send(oauthWebResponse.getBody()); exchange.endExchange(); queue.add(Boolean.TRUE); } }
public AsyncNoBundler() { thread_pool=new ThreadPoolExecutor(0, max_threads, 30000, TimeUnit.MICROSECONDS, new SynchronousQueue<>(), new DefaultThreadFactory("async-bundler", true, true), new ThreadPoolExecutor.CallerRunsPolicy()); thread_pool.allowCoreThreadTimeOut(true); }
/** * Create the BlockingQueue to use for the ThreadPoolExecutor. * <p>A LinkedBlockingQueue instance will be created for a positive * capacity value; a SynchronousQueue else. * @param queueCapacity the specified queue capacity * @return the BlockingQueue instance * @see java.util.concurrent.LinkedBlockingQueue * @see java.util.concurrent.SynchronousQueue */ protected BlockingQueue<Runnable> createQueue(int queueCapacity) { if (queueCapacity > 0) { return new LinkedBlockingQueue<>(queueCapacity); } else { return new SynchronousQueue<>(); } }
@Override public OAuthTokenFinish call() throws Exception { logger.log(Level.INFO, "Waiting for token response"); final String urlWithIdAndToken = (String) ioQueue.take(); logger.log(Level.INFO, "Parsing token response " + urlWithIdAndToken); OAuthTokenFinish tokenResponse = null; // null if parsing failed (user canceled, api error, ... try { tokenResponse = extractor.parse(urlWithIdAndToken); ioQueue.put(OAuthWebResponses.createValidResponse()); } catch (NoSuchFieldException e) { logger.log(Level.SEVERE, "Unable to find token in response", e); ioQueue.put(OAuthWebResponses.createBadResponse()); } ioQueue.take(); // make sure undertow has send a response stop(); logger.log(Level.INFO, tokenResponse != null ? "Returning token" : "No token received, returning null"); return tokenResponse; }
@Override public String urlArg(String argName) { try { Comm c = getUrlArgComm(); HashMap<String, Serializable> data = new HashMap<>(); HashMap<String, Serializable> state = new HashMap<>(); state.put("name", "URL_ARG"); state.put("arg_name", argName); data.put("url", KernelManager.get().getBeakerXServer().getURL() + URL_ARG); data.put("type", "rest"); data.put("state", state); data.put("buffer_paths", new HashMap<>()); c.send(COMM_MSG, Comm.Buffer.EMPTY, new Comm.Data(data)); // block Object argNameValue = getMessageQueue(URL_ARG).take(); return (String) argNameValue; } catch (Exception e) { throw new RuntimeException(e); } }
public ThreadPoolExecutor build() { threadFactory = createThreadFactory(threadFactory, threadNamePrefix, daemon); if (rejectHandler == null) { rejectHandler = defaultRejectHandler; } return new ThreadPoolExecutor(minSize, maxSize, keepAliveSecs, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory, rejectHandler); } }
private static ThreadPoolExecutor getThreadPoolExecutor() { int corePoolSize = 3; int maxPoolSize = Integer.MAX_VALUE; int keepAliveTime = 3; ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory(ThreadPool.class.getSimpleName())); executor.allowCoreThreadTimeOut(true); return executor; }