Java 8 SynchronousQueue - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SynchronousQueue class.

This code example shows how to use the following methods:poll
            throw new TimeoutException("Failed to acquire request scheduler slot for '" + key + "'");
    } 
 
    public Thread poll()
    { 
        Entry e = queue.poll();
        if (e == null)
            return null; 
        metric.addNano(System.nanoTime() - e.creationTime);
        return e.thread;
    } 
 
    @Override 
    public String toString()
    { 
        return "RoundRobinScheduler.WeightedQueue(key=" + key + " weight=" + weight + ")";
    } 
 
    private final static class Entry 
    { 
7
CodeRank
This code example shows how to use the following methods:
 * @see ERXTaskThread 
 * @see ERXExecutorService 
 *  
 */ 
public class ERXExecutorService { 
	private static final ExecutorService _executorService = new ERXTaskThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, 
					TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ERXTaskThreadFactory()); 
 
	/**  
	 * @return a global ExecutorService with no limit for executing runnables.  
	 **/ 
	public static ExecutorService executorService() { 
		return _executorService; 
	} 
 
	/** 
	 * This ExecutorService is useful when you want to execute tasks in parallel, but you want to (create and) 
	 * submit new tasks for execution only when the pool has at least one idle thread. 
	 *  
	 * A task will be rejected with a {@link RejectedExecutionException} when all the threads are busy 
7
CodeRank
This code example shows how to use the following methods:
 
        @Override 
        public synchronized void start(final StartContext context) throws StartException {
            executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                    5L, TimeUnit.SECONDS,
                    new SynchronousQueue<Runnable>(),
                    threadFactory);
        } 
 
        @Override 
        public synchronized void stop(final StopContext context) {
            Thread executorShutdown = new Thread(new Runnable() {
                @Override 
                public void run() { 
                    try { 
                        executorService.shutdown();
                    } finally { 
                        executorService = null;
                        context.complete();
                    } 
7
CodeRank
This code example shows how to use the following methods:
	protected BlockingQueue<Runnable> createQueue(int queueCapacity) {
		if (queueCapacity > 0) {
			return new LinkedBlockingQueue<Runnable>(queueCapacity);
		} 
		else { 
			return new SynchronousQueue<Runnable>();
		} 
	} 
 
 
	@Override 
	public ExecutorService getObject() throws Exception {
		return this.exposedExecutor;
	} 
 
	@Override 
	public Class<? extends ExecutorService> getObjectType() {
		return (this.exposedExecutor != null ? this.exposedExecutor.getClass() : ExecutorService.class);
	} 
 
6
CodeRank
This code example shows how to use the following methods:
    return new ZoieThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, 
        new LinkedBlockingQueue<Runnable>(), threadFactory); 
  } 
 
  public static ExecutorService newCachedThreadPool() { 
    return new ZoieThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, 
        new SynchronousQueue<Runnable>()); 
  } 
 
  public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { 
    return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, 
        new SynchronousQueue<Runnable>(), threadFactory); 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:take
public class GeckoBackgroundThread extends Thread {
    private static final String LOOPER_NAME = "GeckoBackgroundThread";
 
    // Guarded by 'this'. 
    private static Handler sHandler = null;
    private SynchronousQueue<Handler> mHandlerQueue = new SynchronousQueue<Handler>();
 
    // Singleton, so private constructor. 
    private GeckoBackgroundThread() { 
        super(); 
    } 
 
    public void run() { 
        setName(LOOPER_NAME);
        Looper.prepare();
        try { 
            mHandlerQueue.put(new Handler());
        } catch (InterruptedException ie) {}
 
        Looper.loop();

6
CodeRank
This code example shows how to use the following methods:
 
public class Application { 
	public static final String MESSAGE_DONE = "Done";
 
	public static void main(String... args) {
		BlockingQueue<String> queue = new SynchronousQueue<>();
		(new Thread(new Producer(queue))).start();
		(new Thread(new Consumer(queue))).start();
	} 
} 
6
CodeRank
This code example shows how to use the following methods:poll, put, take
    } 
 
    private void error(String msg) {
        Log.e(LOGTAG, msg);
        try { 
            mDataQueue.put("ERROR\n" + msg + "\n");
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } 
    } 
 
    private void eglError(EGL10 egl, String msg) {
        error(msg + " (EGL error " + Integer.toHexString(egl.eglGetError()) + ")");
    } 
 
    public String getData() {
        String data = mDataQueue.poll();
        if (data != null)
            return data;
 

6
CodeRank
This code example shows how to use the following methods:
	protected BlockingQueue<Runnable> createQueue(int queueCapacity) {
		if (queueCapacity > 0) {
			return new LinkedBlockingQueue<Runnable>(queueCapacity);
		} 
		else { 
			return new SynchronousQueue<Runnable>();
		} 
	} 
 
	/** 
	 * Return the underlying ThreadPoolExecutor for native access. 
	 * @return the underlying ThreadPoolExecutor (never {@code null}) 
	 * @throws IllegalStateException if the ThreadPoolTaskExecutor hasn't been initialized yet 
	 */ 
	public ThreadPoolExecutor getThreadPoolExecutor() throws IllegalStateException {
		Assert.state(this.threadPoolExecutor != null, "ThreadPoolTaskExecutor not initialized");
		return this.threadPoolExecutor;
	} 
 
	/** 
6
CodeRank
This code example shows how to use the following methods:
 * @author Mark Fisher 
 */ 
public class RendezvousChannel extends QueueChannel { 
 
	public RendezvousChannel() { 
		super(new SynchronousQueue<Message<?>>()); 
	} 
 
} 
6
CodeRank
See Code Examples for Java 8 SynchronousQueue Methods: