src/share/classes/java/lang/Thread.java

Print this page




 212     private int threadStatus = 0;
 213 
 214 
 215     private static synchronized long nextThreadID() {
 216         return ++threadSeqNumber;
 217     }
 218 
 219     /**
 220      * The argument supplied to the current call to
 221      * java.util.concurrent.locks.LockSupport.park.
 222      * Set by (private) java.util.concurrent.locks.LockSupport.setBlocker
 223      * Accessed using java.util.concurrent.locks.LockSupport.getBlocker
 224      */
 225     volatile Object parkBlocker;
 226 
 227     /* The object in which this thread is blocked in an interruptible I/O
 228      * operation, if any.  The blocker's interrupt method should be invoked
 229      * after setting this thread's interrupt status.
 230      */
 231     private volatile Interruptible blocker;
 232     private Object blockerLock = new Object();
 233 
 234     /* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
 235      */
 236     void blockedOn(Interruptible b) {
 237         synchronized (blockerLock) {
 238             blocker = b;
 239         }
 240     }
 241 
 242     /**
 243      * The minimum priority that a thread can have.
 244      */
 245     public final static int MIN_PRIORITY = 1;
 246 
 247    /**
 248      * The default priority that is assigned to a thread.
 249      */
 250     public final static int NORM_PRIORITY = 5;
 251 
 252     /**


 671      * In particular, a thread may not be restarted once it has completed
 672      * execution.
 673      *
 674      * @exception  IllegalThreadStateException  if the thread was already
 675      *               started.
 676      * @see        #run()
 677      * @see        #stop()
 678      */
 679     public synchronized void start() {
 680         /**
 681          * This method is not invoked for the main method thread or "system"
 682          * group threads created/set up by the VM. Any new functionality added
 683          * to this method in the future may have to also be added to the VM.
 684          *
 685          * A zero status value corresponds to state "NEW".
 686          */
 687         if (threadStatus != 0)
 688             throw new IllegalThreadStateException();
 689 
 690         /* Notify the group that this thread is about to be started
 691          * so that it can be added to the group's list of threads. */

 692         group.threadStarting(this);
 693 
 694         boolean failed = true;
 695         try {
 696             start0();
 697             failed = false;
 698         } finally {
 699             try {
 700                 group.threadStarted(this, failed);


 701             } catch (Throwable ignore) {
 702                 /* do nothing. If start0 threw a Throwable then
 703                   it will be passed up the call stack */
 704             }
 705         }
 706 
 707         if (stopBeforeStart) {
 708             stop0(throwableFromStop);
 709         }
 710     }
 711 
 712     private native void start0();
 713 
 714     /**
 715      * If this thread was constructed using a separate
 716      * <code>Runnable</code> run object, then that
 717      * <code>Runnable</code> object's <code>run</code> method is called;
 718      * otherwise, this method does nothing and returns.
 719      * <p>
 720      * Subclasses of <code>Thread</code> should override this method.




 212     private int threadStatus = 0;
 213 
 214 
 215     private static synchronized long nextThreadID() {
 216         return ++threadSeqNumber;
 217     }
 218 
 219     /**
 220      * The argument supplied to the current call to
 221      * java.util.concurrent.locks.LockSupport.park.
 222      * Set by (private) java.util.concurrent.locks.LockSupport.setBlocker
 223      * Accessed using java.util.concurrent.locks.LockSupport.getBlocker
 224      */
 225     volatile Object parkBlocker;
 226 
 227     /* The object in which this thread is blocked in an interruptible I/O
 228      * operation, if any.  The blocker's interrupt method should be invoked
 229      * after setting this thread's interrupt status.
 230      */
 231     private volatile Interruptible blocker;
 232     private final Object blockerLock = new Object();
 233 
 234     /* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
 235      */
 236     void blockedOn(Interruptible b) {
 237         synchronized (blockerLock) {
 238             blocker = b;
 239         }
 240     }
 241 
 242     /**
 243      * The minimum priority that a thread can have.
 244      */
 245     public final static int MIN_PRIORITY = 1;
 246 
 247    /**
 248      * The default priority that is assigned to a thread.
 249      */
 250     public final static int NORM_PRIORITY = 5;
 251 
 252     /**


 671      * In particular, a thread may not be restarted once it has completed
 672      * execution.
 673      *
 674      * @exception  IllegalThreadStateException  if the thread was already
 675      *               started.
 676      * @see        #run()
 677      * @see        #stop()
 678      */
 679     public synchronized void start() {
 680         /**
 681          * This method is not invoked for the main method thread or "system"
 682          * group threads created/set up by the VM. Any new functionality added
 683          * to this method in the future may have to also be added to the VM.
 684          *
 685          * A zero status value corresponds to state "NEW".
 686          */
 687         if (threadStatus != 0)
 688             throw new IllegalThreadStateException();
 689 
 690         /* Notify the group that this thread is about to be started
 691          * so that it can be added to the group's list of threads
 692          * and the group's unstarted count can be decremented. */
 693         group.threadStarting(this);
 694 
 695         boolean started = false;
 696         try {
 697             start0();
 698             started = true;
 699         } finally {
 700             try {
 701                 if (!started) {
 702                     group.threadStartFailed(this);
 703                 }
 704             } catch (Throwable ignore) {
 705                 /* do nothing. If start0 threw a Throwable then
 706                   it will be passed up the call stack */
 707             }
 708         }
 709 
 710         if (stopBeforeStart) {
 711             stop0(throwableFromStop);
 712         }
 713     }
 714 
 715     private native void start0();
 716 
 717     /**
 718      * If this thread was constructed using a separate
 719      * <code>Runnable</code> run object, then that
 720      * <code>Runnable</code> object's <code>run</code> method is called;
 721      * otherwise, this method does nothing and returns.
 722      * <p>
 723      * Subclasses of <code>Thread</code> should override this method.