Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java
          +++ new/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java
↓ open down ↓ 1833 lines elided ↑ open up ↑
1834 1834          try {
1835 1835              long n = completedTaskCount;
1836 1836              for (Worker w : workers)
1837 1837                  n += w.completedTasks;
1838 1838              return n;
1839 1839          } finally {
1840 1840              mainLock.unlock();
1841 1841          }
1842 1842      }
1843 1843  
     1844 +    /**
     1845 +     * Returns a string identifying this pool, as well as its state,
     1846 +     * including indications of run state and estimated worker and
     1847 +     * task counts.
     1848 +     *
     1849 +     * @return a string identifying this pool, as well as its state
     1850 +     */
     1851 +    public String toString() {
     1852 +        long ncompleted;
     1853 +        int nworkers, nactive;
     1854 +        final ReentrantLock mainLock = this.mainLock;
     1855 +        mainLock.lock();
     1856 +        try {
     1857 +            ncompleted = completedTaskCount;
     1858 +            nactive = 0;
     1859 +            nworkers = workers.size();
     1860 +            for (Worker w : workers) {
     1861 +                ncompleted += w.completedTasks;
     1862 +                if (w.isLocked())
     1863 +                    ++nactive;
     1864 +            }
     1865 +        } finally {
     1866 +            mainLock.unlock();
     1867 +        }
     1868 +        int c = ctl.get();
     1869 +        String rs = (runStateLessThan(c, SHUTDOWN) ? "Running" :
     1870 +                     (runStateAtLeast(c, TERMINATED) ? "Terminated" :
     1871 +                      "Shutting down"));
     1872 +        return super.toString() +
     1873 +            "[" + rs +
     1874 +            ", pool size = " + nworkers +
     1875 +            ", active threads = " + nactive +
     1876 +            ", queued tasks = " + workQueue.size() +
     1877 +            ", completed tasks = " + ncompleted +
     1878 +            "]";
     1879 +    }
     1880 +
1844 1881      /* Extension hooks */
1845 1882  
1846 1883      /**
1847 1884       * Method invoked prior to executing the given Runnable in the
1848 1885       * given thread.  This method is invoked by thread {@code t} that
1849 1886       * will execute task {@code r}, and may be used to re-initialize
1850 1887       * ThreadLocals, or to perform logging.
1851 1888       *
1852 1889       * <p>This implementation does nothing, but may be customized in
1853 1890       * subclasses. Note: To properly nest multiple overridings, subclasses
↓ open down ↓ 100 lines elided ↑ open up ↑
1954 1991          public AbortPolicy() { }
1955 1992  
1956 1993          /**
1957 1994           * Always throws RejectedExecutionException.
1958 1995           *
1959 1996           * @param r the runnable task requested to be executed
1960 1997           * @param e the executor attempting to execute this task
1961 1998           * @throws RejectedExecutionException always.
1962 1999           */
1963 2000          public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
1964      -            throw new RejectedExecutionException();
     2001 +            throw new RejectedExecutionException("Task " + r.toString() +
     2002 +                                                 " rejected from " +
     2003 +                                                 e.toString());
1965 2004          }
1966 2005      }
1967 2006  
1968 2007      /**
1969 2008       * A handler for rejected tasks that silently discards the
1970 2009       * rejected task.
1971 2010       */
1972 2011      public static class DiscardPolicy implements RejectedExecutionHandler {
1973 2012          /**
1974 2013           * Creates a {@code DiscardPolicy}.
↓ open down ↓ 41 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX