ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.10 by jsr166, Mon Jul 20 23:07:43 2009 UTC vs.
Revision 1.13 by jsr166, Wed Jul 22 01:36:51 2009 UTC

# Line 56 | Line 56 | import java.lang.reflect.*;
56   * maximum number of running threads to 32767. Attempts to create
57   * pools with greater than the maximum result in
58   * IllegalArgumentExceptions.
59 + *
60 + * @since 1.7
61 + * @author Doug Lea
62   */
63   public class ForkJoinPool extends AbstractExecutorService {
64  
# Line 81 | Line 84 | public class ForkJoinPool extends Abstra
84           * Returns a new worker thread operating in the given pool.
85           *
86           * @param pool the pool this thread works in
87 <         * @throws NullPointerException if pool is null;
87 >         * @throws NullPointerException if pool is null
88           */
89          public ForkJoinWorkerThread newThread(ForkJoinPool pool);
90      }
# Line 273 | Line 276 | public class ForkJoinPool extends Abstra
276      /**
277       * Try incrementing active count; fail on contention. Called by
278       * workers before/during executing tasks.
279 <     * @return true on success;
279 >     * @return true on success
280       */
281      final boolean tryIncrementActiveCount() {
282          int c = runControl;
# Line 376 | Line 379 | public class ForkJoinPool extends Abstra
379       * @param parallelism the targeted number of worker threads
380       * @param factory the factory for creating new threads
381       * @throws IllegalArgumentException if parallelism less than or
382 <     * equal to zero, or greater than implementation limit.
382 >     * equal to zero, or greater than implementation limit
383       * @throws NullPointerException if factory is null
384       * @throws SecurityException if a security manager exists and
385       *         the caller is not permitted to modify threads
# Line 719 | Line 722 | public class ForkJoinPool extends Abstra
722       * Sets the target parallelism level of this pool.
723       * @param parallelism the target parallelism
724       * @throws IllegalArgumentException if parallelism less than or
725 <     * equal to zero or greater than maximum size bounds.
725 >     * equal to zero or greater than maximum size bounds
726       * @throws SecurityException if a security manager exists and
727       *         the caller is not permitted to modify threads
728       *         because it does not hold {@link
# Line 782 | Line 785 | public class ForkJoinPool extends Abstra
785       * Setting this value has no effect on current pool size. It
786       * controls construction of new threads.
787       * @throws IllegalArgumentException if negative or greater then
788 <     * internal implementation limit.
788 >     * internal implementation limit
789       */
790      public void setMaximumPoolSize(int newMax) {
791          if (newMax < 0 || newMax > MAX_THREADS)
# Line 822 | Line 825 | public class ForkJoinPool extends Abstra
825       * invocations at other times may be unpredictable.
826       *
827       * @param async if true, use locally FIFO scheduling
828 <     * @return the previous mode.
828 >     * @return the previous mode
829       */
830      public boolean setAsyncMode(boolean async) {
831          boolean oldMode = locallyFifo;
# Line 842 | Line 845 | public class ForkJoinPool extends Abstra
845       * Returns true if this pool uses local first-in-first-out
846       * scheduling mode for forked tasks that are never joined.
847       *
848 <     * @return true if this pool uses async mode.
848 >     * @return true if this pool uses async mode
849       */
850      public boolean getAsyncMode() {
851          return locallyFifo;
# Line 863 | Line 866 | public class ForkJoinPool extends Abstra
866       * Returns an estimate of the number of threads that are currently
867       * stealing or executing tasks. This method may overestimate the
868       * number of active threads.
869 <     * @return the number of active threads.
869 >     * @return the number of active threads
870       */
871      public int getActiveThreadCount() {
872          return activeCountOf(runControl);
# Line 873 | Line 876 | public class ForkJoinPool extends Abstra
876       * Returns an estimate of the number of threads that are currently
877       * idle waiting for tasks. This method may underestimate the
878       * number of idle threads.
879 <     * @return the number of idle threads.
879 >     * @return the number of idle threads
880       */
881      final int getIdleThreadCount() {
882          int c = runningCountOf(workerCounts) - activeCountOf(runControl);
# Line 902 | Line 905 | public class ForkJoinPool extends Abstra
905       * tuning fork/join programs: In general, steal counts should be
906       * high enough to keep threads busy, but low enough to avoid
907       * overhead and contention across threads.
908 <     * @return the number of steals.
908 >     * @return the number of steals
909       */
910      public long getStealCount() {
911          return stealCount.get();
# Line 925 | Line 928 | public class ForkJoinPool extends Abstra
928       * an approximation, obtained by iterating across all threads in
929       * the pool. This method may be useful for tuning task
930       * granularities.
931 <     * @return the number of queued tasks.
931 >     * @return the number of queued tasks
932       */
933      public long getQueuedTaskCount() {
934          long count = 0;
# Line 944 | Line 947 | public class ForkJoinPool extends Abstra
947       * Returns an estimate of the number tasks submitted to this pool
948       * that have not yet begun executing. This method takes time
949       * proportional to the number of submissions.
950 <     * @return the number of queued submissions.
950 >     * @return the number of queued submissions
951       */
952      public int getQueuedSubmissionCount() {
953          return submissionQueue.size();
# Line 953 | Line 956 | public class ForkJoinPool extends Abstra
956      /**
957       * Returns true if there are any tasks submitted to this pool
958       * that have not yet begun executing.
959 <     * @return {@code true} if there are any queued submissions.
959 >     * @return {@code true} if there are any queued submissions
960       */
961      public boolean hasQueuedSubmissions() {
962          return !submissionQueue.isEmpty();
# Line 1717 | Line 1720 | public class ForkJoinPool extends Abstra
1720           * Possibly blocks the current thread, for example waiting for
1721           * a lock or condition.
1722           * @return true if no additional blocking is necessary (i.e.,
1723 <         * if isReleasable would return true).
1723 >         * if isReleasable would return true)
1724           * @throws InterruptedException if interrupted while waiting
1725           * (the method is not required to do so, but is allowed to).
1726           */
# Line 1756 | Line 1759 | public class ForkJoinPool extends Abstra
1759       * attempt to maintain the pool's nominal parallelism; otherwise
1760       * activate a thread only if necessary to avoid complete
1761       * starvation.
1762 <     * @throws InterruptedException if blocker.block did so.
1762 >     * @throws InterruptedException if blocker.block did so
1763       */
1764      public static void managedBlock(ManagedBlocker blocker,
1765                                      boolean maintainParallelism)
# Line 1818 | Line 1821 | public class ForkJoinPool extends Abstra
1821  
1822      private static long fieldOffset(String fieldName)
1823              throws NoSuchFieldException {
1824 <        return _unsafe.objectFieldOffset
1824 >        return UNSAFE.objectFieldOffset
1825              (ForkJoinPool.class.getDeclaredField(fieldName));
1826      }
1827  
1828 <    static final Unsafe _unsafe;
1828 >    static final Unsafe UNSAFE;
1829      static final long eventCountOffset;
1830      static final long workerCountsOffset;
1831      static final long runControlOffset;
# Line 1831 | Line 1834 | public class ForkJoinPool extends Abstra
1834  
1835      static {
1836          try {
1837 <            _unsafe = getUnsafe();
1837 >            UNSAFE = getUnsafe();
1838              eventCountOffset = fieldOffset("eventCount");
1839              workerCountsOffset = fieldOffset("workerCounts");
1840              runControlOffset = fieldOffset("runControl");
# Line 1843 | Line 1846 | public class ForkJoinPool extends Abstra
1846      }
1847  
1848      private boolean casEventCount(long cmp, long val) {
1849 <        return _unsafe.compareAndSwapLong(this, eventCountOffset, cmp, val);
1849 >        return UNSAFE.compareAndSwapLong(this, eventCountOffset, cmp, val);
1850      }
1851      private boolean casWorkerCounts(int cmp, int val) {
1852 <        return _unsafe.compareAndSwapInt(this, workerCountsOffset, cmp, val);
1852 >        return UNSAFE.compareAndSwapInt(this, workerCountsOffset, cmp, val);
1853      }
1854      private boolean casRunControl(int cmp, int val) {
1855 <        return _unsafe.compareAndSwapInt(this, runControlOffset, cmp, val);
1855 >        return UNSAFE.compareAndSwapInt(this, runControlOffset, cmp, val);
1856      }
1857      private boolean casSpareStack(WaitQueueNode cmp, WaitQueueNode val) {
1858 <        return _unsafe.compareAndSwapObject(this, spareStackOffset, cmp, val);
1858 >        return UNSAFE.compareAndSwapObject(this, spareStackOffset, cmp, val);
1859      }
1860      private boolean casBarrierStack(WaitQueueNode cmp, WaitQueueNode val) {
1861 <        return _unsafe.compareAndSwapObject(this, syncStackOffset, cmp, val);
1861 >        return UNSAFE.compareAndSwapObject(this, syncStackOffset, cmp, val);
1862      }
1863   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines