Home > Back-end >  Why didn't ThreadLocal, after gc ThreadLocal be recycled?
Why didn't ThreadLocal, after gc ThreadLocal be recycled?

Time:03-20


/* ** ThreadLocal do not support inheritance 
* add by duyang 06 28 2019
*/
Public class ThreadLocalTest {


/* *
* InheritableThreadLocal child thread can access the parent thread variables;
*/
//private static ThreadLocal Are=new ThreadLocal<> (a);
Public static void main (String [] args) throws InterruptedException {
ThreadLocal Are=new ThreadLocal<> (a);
Are set (called "lian");
System. The gc ();
System. Out. Println (Thread. CurrentThread () + "" + are the get ());
//delete ThreadLocal
//are. Remove ();
}
}


16 lines of code and what value that GC no recycling ThreadLocal? Have a great god to

CodePudding user response:

Execution System. The role of the gc () function is just to remind or tell the virtual machine, wants a garbage collection, as to when to recycle depends on the virtual machine, and there is no guarantee that a certain recycle
  • Related