< prev index next >

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

Print this page
rev 48993 : imported patch nio


 214     }
 215 
 216     /**
 217      * The argument supplied to the current call to
 218      * java.util.concurrent.locks.LockSupport.park.
 219      * Set by (private) java.util.concurrent.locks.LockSupport.setBlocker
 220      * Accessed using java.util.concurrent.locks.LockSupport.getBlocker
 221      */
 222     volatile Object parkBlocker;
 223 
 224     /* The object in which this thread is blocked in an interruptible I/O
 225      * operation, if any.  The blocker's interrupt method should be invoked
 226      * after setting this thread's interrupt status.
 227      */
 228     private volatile Interruptible blocker;
 229     private final Object blockerLock = new Object();
 230 
 231     /* Set the blocker field; invoked via jdk.internal.misc.SharedSecrets
 232      * from java.nio code
 233      */
 234     void blockedOn(Interruptible b) {
 235         synchronized (blockerLock) {
 236             blocker = b;

 237         }
 238     }
 239 
 240     /**
 241      * The minimum priority that a thread can have.
 242      */
 243     public static final int MIN_PRIORITY = 1;
 244 
 245    /**
 246      * The default priority that is assigned to a thread.
 247      */
 248     public static final int NORM_PRIORITY = 5;
 249 
 250     /**
 251      * The maximum priority that a thread can have.
 252      */
 253     public static final int MAX_PRIORITY = 10;
 254 
 255     /**
 256      * Returns a reference to the currently executing thread object.


 989      * java.nio.channels.ClosedByInterruptException}.
 990      *
 991      * <p> If this thread is blocked in a {@link java.nio.channels.Selector}
 992      * then the thread's interrupt status will be set and it will return
 993      * immediately from the selection operation, possibly with a non-zero
 994      * value, just as if the selector's {@link
 995      * java.nio.channels.Selector#wakeup wakeup} method were invoked.
 996      *
 997      * <p> If none of the previous conditions hold then this thread's interrupt
 998      * status will be set. </p>
 999      *
1000      * <p> Interrupting a thread that is not alive need not have any effect.
1001      *
1002      * @throws  SecurityException
1003      *          if the current thread cannot modify this thread
1004      *
1005      * @revised 6.0
1006      * @spec JSR-51
1007      */
1008     public void interrupt() {
1009         if (this != Thread.currentThread())

1010             checkAccess();
1011 





1012         synchronized (blockerLock) {
1013             Interruptible b = blocker;
1014             if (b != null) {
1015                 interrupt0();           // Just to set the interrupt flag
1016                 b.interrupt(this);
1017                 return;
1018             }
1019         }
1020         interrupt0();
1021     }
1022 
1023     /**
1024      * Tests whether the current thread has been interrupted.  The
1025      * <i>interrupted status</i> of the thread is cleared by this method.  In
1026      * other words, if this method were to be called twice in succession, the
1027      * second call would return false (unless the current thread were
1028      * interrupted again, after the first call had cleared its interrupted
1029      * status and before the second call had examined it).
1030      *
1031      * <p>A thread interruption ignored because a thread was not alive
1032      * at the time of the interrupt will be reflected by this method
1033      * returning false.
1034      *
1035      * @return  <code>true</code> if the current thread has been interrupted;
1036      *          <code>false</code> otherwise.
1037      * @see #isInterrupted()
1038      * @revised 6.0
1039      */
1040     public static boolean interrupted() {




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


 990      * java.nio.channels.ClosedByInterruptException}.
 991      *
 992      * <p> If this thread is blocked in a {@link java.nio.channels.Selector}
 993      * then the thread's interrupt status will be set and it will return
 994      * immediately from the selection operation, possibly with a non-zero
 995      * value, just as if the selector's {@link
 996      * java.nio.channels.Selector#wakeup wakeup} method were invoked.
 997      *
 998      * <p> If none of the previous conditions hold then this thread's interrupt
 999      * status will be set. </p>
1000      *
1001      * <p> Interrupting a thread that is not alive need not have any effect.
1002      *
1003      * @throws  SecurityException
1004      *          if the current thread cannot modify this thread
1005      *
1006      * @revised 6.0
1007      * @spec JSR-51
1008      */
1009     public void interrupt() {
1010         Thread me = Thread.currentThread();
1011         if (this != me)
1012             checkAccess();
1013 
1014         // set interrupt status
1015         interrupt0();
1016 
1017         // thread may be blocked in an I/O operation
1018         if (this != me && blocker != null) {
1019             synchronized (blockerLock) {
1020                 Interruptible b = blocker;
1021                 if (b != null) {

1022                     b.interrupt(this);

1023                 }
1024             }
1025         }
1026     }
1027 
1028     /**
1029      * Tests whether the current thread has been interrupted.  The
1030      * <i>interrupted status</i> of the thread is cleared by this method.  In
1031      * other words, if this method were to be called twice in succession, the
1032      * second call would return false (unless the current thread were
1033      * interrupted again, after the first call had cleared its interrupted
1034      * status and before the second call had examined it).
1035      *
1036      * <p>A thread interruption ignored because a thread was not alive
1037      * at the time of the interrupt will be reflected by this method
1038      * returning false.
1039      *
1040      * @return  <code>true</code> if the current thread has been interrupted;
1041      *          <code>false</code> otherwise.
1042      * @see #isInterrupted()
1043      * @revised 6.0
1044      */
1045     public static boolean interrupted() {


< prev index next >