1

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?

1
  • How exactly does the object "run a repeated thread"? What does this mean? Threads run by themselves, and they are started by other threads. Objects don't "do" anything. They just sit there. Commented Jul 5, 2014 at 2:32

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, but wouldn't Java's garbage collector eventually dispose of the object's resources?
@user1625168 Every object that is reachable from the stack of a running thread is "live" to the GC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.