Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/lang/Thread.java
          +++ new/src/share/classes/java/lang/Thread.java
↓ open down ↓ 246 lines elided ↑ open up ↑
 247  247     /**
 248  248       * The default priority that is assigned to a thread.
 249  249       */
 250  250      public final static int NORM_PRIORITY = 5;
 251  251  
 252  252      /**
 253  253       * The maximum priority that a thread can have.
 254  254       */
 255  255      public final static int MAX_PRIORITY = 10;
 256  256  
 257      -    /* If stop was called before start */
 258      -    private boolean stopBeforeStart;
 259      -
 260      -    /* Remembered Throwable from stop before start */
 261      -    private Throwable throwableFromStop;
 262      -
 263  257      /**
 264  258       * Returns a reference to the currently executing thread object.
 265  259       *
 266  260       * @return  the currently executing thread.
 267  261       */
 268  262      public static native Thread currentThread();
 269  263  
 270  264      /**
 271  265       * A hint to the scheduler that the current thread is willing to yield
 272  266       * its current use of a processor. The scheduler is free to ignore this
↓ open down ↓ 426 lines elided ↑ open up ↑
 699  693          } finally {
 700  694              try {
 701  695                  if (!started) {
 702  696                      group.threadStartFailed(this);
 703  697                  }
 704  698              } catch (Throwable ignore) {
 705  699                  /* do nothing. If start0 threw a Throwable then
 706  700                    it will be passed up the call stack */
 707  701              }
 708  702          }
 709      -
 710      -        if (stopBeforeStart) {
 711      -            stop0(throwableFromStop);
 712      -        }
 713  703      }
 714  704  
 715  705      private native void start0();
 716  706  
 717  707      /**
 718  708       * If this thread was constructed using a separate
 719  709       * <code>Runnable</code> run object, then that
 720  710       * <code>Runnable</code> object's <code>run</code> method is called;
 721  711       * otherwise, this method does nothing and returns.
 722  712       * <p>
↓ open down ↓ 90 lines elided ↑ open up ↑
 813  803       *       if the variable indicates that it is to stop running.  If the
 814  804       *       target thread waits for long periods (on a condition variable,
 815  805       *       for example), the <code>interrupt</code> method should be used to
 816  806       *       interrupt the wait.
 817  807       *       For more information, see
 818  808       *       <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html">Why
 819  809       *       are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
 820  810       */
 821  811      @Deprecated
 822  812      public final void stop() {
 823      -        // If the thread is already dead, return.
 824      -        // A zero status value corresponds to "NEW".
 825      -        if ((threadStatus != 0) && !isAlive()) {
 826      -            return;
 827      -        }
 828      -        stop1(new ThreadDeath());
      813 +        stop(new ThreadDeath());
 829  814      }
 830  815  
 831  816      /**
 832  817       * Forces the thread to stop executing.
 833  818       * <p>
 834  819       * If there is a security manager installed, the <code>checkAccess</code>
 835  820       * method of this thread is called, which may result in a
 836  821       * <code>SecurityException</code> being raised (in the current thread).
 837  822       * <p>
 838  823       * If this thread is different from the current thread (that is, the current
↓ open down ↓ 33 lines elided ↑ open up ↑
 872  857       *        method is that it may be used to generate exceptions that the
 873  858       *        target thread is unprepared to handle (including checked
 874  859       *        exceptions that the thread could not possibly throw, were it
 875  860       *        not for this method).
 876  861       *        For more information, see
 877  862       *        <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html">Why
 878  863       *        are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
 879  864       */
 880  865      @Deprecated
 881  866      public final synchronized void stop(Throwable obj) {
 882      -        stop1(obj);
 883      -    }
 884      -
 885      -    /**
 886      -     * Common impl for stop() and stop(Throwable).
 887      -     */
 888      -    private final synchronized void stop1(Throwable th) {
 889  867          SecurityManager security = System.getSecurityManager();
 890  868          if (security != null) {
 891  869              checkAccess();
 892  870              if ((this != Thread.currentThread()) ||
 893      -                (!(th instanceof ThreadDeath))) {
      871 +                (!(obj instanceof ThreadDeath))) {
 894  872                  security.checkPermission(SecurityConstants.STOP_THREAD_PERMISSION);
 895  873              }
 896  874          }
 897      -        // A zero status value corresponds to "NEW"
      875 +        // A zero status value corresponds to "NEW", it can't change to
      876 +        // not-NEW because we hold the lock.
 898  877          if (threadStatus != 0) {
 899  878              resume(); // Wake up thread if it was suspended; no-op otherwise
 900      -            stop0(th);
 901      -        } else {
 902      -
 903      -            // Must do the null arg check that the VM would do with stop0
 904      -            if (th == null) {
 905      -                throw new NullPointerException();
 906      -            }
 907      -
 908      -            // Remember this stop attempt for if/when start is used
 909      -            stopBeforeStart = true;
 910      -            throwableFromStop = th;
 911  879          }
      880 +        
      881 +        // The VM can handle all thread states
      882 +        stop0(obj);
 912  883      }
 913  884  
 914  885      /**
 915  886       * Interrupts this thread.
 916  887       *
 917  888       * <p> Unless the current thread is interrupting itself, which is
 918  889       * always permitted, the {@link #checkAccess() checkAccess} method
 919  890       * of this thread is invoked, which may cause a {@link
 920  891       * SecurityException} to be thrown.
 921  892       *
↓ open down ↓ 1140 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX