/** * Constructs a <code>DefaultThreadPoolExecutor</code> with configuration that * matches the return from {@link java.util.concurrent.Executors#newCachedThreadPool()}. */ public DefaultThreadPoolExecutor() { super(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue()); }
/** * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ public int drainTo(Collection c, int maxElements) { if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; Object e; while (n < maxElements && (e = poll()) != null) { c.add(e); ++n; } return n; } }
boolean x = node.waitForTake(nanos); if (!x) unlinkCancelledProducer(node); return x; } catch (InterruptedException ex) { unlinkCancelledProducer(node); throw ex;
Object x = node.waitForPut(nanos); if (x == null) unlinkCancelledConsumer(node); return (Object)x; } catch (InterruptedException ex) { unlinkCancelledConsumer(node); throw ex;
boolean x = node.waitForTake(nanos); if (!x) unlinkCancelledProducer(node); return x; } catch (InterruptedException ex) { unlinkCancelledProducer(node); throw ex;
Object x = node.waitForPut(nanos); if (x == null) unlinkCancelledConsumer(node); return (Object)x; } catch (InterruptedException ex) { unlinkCancelledConsumer(node); throw ex;
/** * Creates a thread pool that creates new threads as needed, but * will reuse previously constructed threads when they are * available, and uses the provided * ThreadFactory to create new threads when needed. * @param threadFactory the factory to use when creating new threads * @return the newly created thread pool * @throws NullPointerException if threadFactory is null */ public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), threadFactory); }
/** * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ public int drainTo(Collection c, int maxElements) { if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; Object e; while (n < maxElements && (e = poll()) != null) { c.add(e); ++n; } return n; } }
boolean x = node.waitForTake(nanos); if (!x) unlinkCancelledProducer(node); return x; } catch (InterruptedException ex) { unlinkCancelledProducer(node); throw ex;
Object x = node.waitForPut(nanos); if (x == null) unlinkCancelledConsumer(node); return (Object)x; } catch (InterruptedException ex) { unlinkCancelledConsumer(node); throw ex;
/** * Creates a thread pool that creates new threads as needed, but * will reuse previously constructed threads when they are * available, and uses the provided * ThreadFactory to create new threads when needed. * @param threadFactory the factory to use when creating new threads * @return the newly created thread pool * @throws NullPointerException if threadFactory is null */ public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), threadFactory); }
/** * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ public int drainTo(Collection c) { if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; Object e; while ( (e = poll()) != null) { c.add(e); ++n; } return n; }
return; } catch (InterruptedException ex) { unlinkCancelledProducer(node); throw ex;
return (Object)x; } catch (InterruptedException ex) { unlinkCancelledConsumer(node); throw ex;
/** * Creates a thread pool that creates new threads as needed, but * will reuse previously constructed threads when they are * available, and uses the provided * ThreadFactory to create new threads when needed. * @param threadFactory the factory to use when creating new threads * @return the newly created thread pool * @throws NullPointerException if threadFactory is null */ public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), threadFactory); }
/** * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ public int drainTo(Collection c) { if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; Object e; while ( (e = poll()) != null) { c.add(e); ++n; } return n; }
return; } catch (InterruptedException ex) { unlinkCancelledProducer(node); throw ex;
return (Object)x; } catch (InterruptedException ex) { unlinkCancelledConsumer(node); throw ex;
/** * Creates a thread pool that creates new threads as needed, but * will reuse previously constructed threads when they are * available. These pools will typically improve the performance * of programs that execute many short-lived asynchronous tasks. * Calls to <tt>execute</tt> will reuse previously constructed * threads if available. If no existing thread is available, a new * thread will be created and added to the pool. Threads that have * not been used for sixty seconds are terminated and removed from * the cache. Thus, a pool that remains idle for long enough will * not consume any resources. Note that pools with similar * properties but different details (for example, timeout parameters) * may be created using {@link ThreadPoolExecutor} constructors. * * @return the newly created thread pool */ public static ExecutorService newCachedThreadPool() { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue()); }
/** * @throws UnsupportedOperationException {@inheritDoc} * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ public int drainTo(Collection c) { if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; Object e; while ( (e = poll()) != null) { c.add(e); ++n; } return n; }