简体   繁体   中英

Java threads within a hashmap

Say I have an object "MyObj" that runs a repeated thread and I place this object within a hash-map.

If I then remove the entry for that object, will this kill the thread? Or do I need to kill the thread before removing the object?

Removing an object from a HashMap will do nothing to the thread, and it will continue to run unless you explicitly stop it.

From Java Memory Management

Active Java threads are always considered live objects and are therefore GC roots. This is especially important for thread local variables

An object must be unreachable and have no GC roots to be considered for GC'ing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM