< prev index next >

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

Print this page
rev 50167 : 8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
Reviewed-by:


 821      * otherwise, this method does nothing and returns.
 822      * <p>
 823      * Subclasses of {@code Thread} should override this method.
 824      *
 825      * @see     #start()
 826      * @see     #stop()
 827      * @see     #Thread(ThreadGroup, Runnable, String)
 828      */
 829     @Override
 830     public void run() {
 831         if (target != null) {
 832             target.run();
 833         }
 834     }
 835 
 836     /**
 837      * This method is called by the system to give a Thread
 838      * a chance to clean up before it actually exits.
 839      */
 840     private void exit() {

 841         if (group != null) {
 842             group.threadTerminated(this);
 843             group = null;
 844         }
 845         /* Aggressively null out all reference fields: see bug 4006245 */
 846         target = null;
 847         /* Speed the release of some of these resources */
 848         threadLocals = null;
 849         inheritableThreadLocals = null;
 850         inheritedAccessControlContext = null;
 851         blocker = null;
 852         uncaughtExceptionHandler = null;
 853     }
 854 
 855     /**
 856      * Forces the thread to stop executing.
 857      * <p>
 858      * If there is a security manager installed, its {@code checkAccess}
 859      * method is called with {@code this}
 860      * as its argument. This may result in a




 821      * otherwise, this method does nothing and returns.
 822      * <p>
 823      * Subclasses of {@code Thread} should override this method.
 824      *
 825      * @see     #start()
 826      * @see     #stop()
 827      * @see     #Thread(ThreadGroup, Runnable, String)
 828      */
 829     @Override
 830     public void run() {
 831         if (target != null) {
 832             target.run();
 833         }
 834     }
 835 
 836     /**
 837      * This method is called by the system to give a Thread
 838      * a chance to clean up before it actually exits.
 839      */
 840     private void exit() {
 841         ThreadLocal.callThreadTerminated(threadLocals);
 842         if (group != null) {
 843             group.threadTerminated(this);
 844             group = null;
 845         }
 846         /* Aggressively null out all reference fields: see bug 4006245 */
 847         target = null;
 848         /* Speed the release of some of these resources */
 849         threadLocals = null;
 850         inheritableThreadLocals = null;
 851         inheritedAccessControlContext = null;
 852         blocker = null;
 853         uncaughtExceptionHandler = null;
 854     }
 855 
 856     /**
 857      * Forces the thread to stop executing.
 858      * <p>
 859      * If there is a security manager installed, its {@code checkAccess}
 860      * method is called with {@code this}
 861      * as its argument. This may result in a


< prev index next >