multithreading - In java, what happens when deleting an object while it is being used? -


here scenario:

  1. i have java hashtable takes string key , object value.

  2. one thread gets object using key , calls method on object.

  3. while method doing operation step b), thread calls remove on particular key references object.

what happens ?

should put lock on operation ?

nothing happens, assuming you're talking (thread-safe) java.util.hashtable. removing object hashtable has no impact on other references object.

objects eligible garbage collection once nothing references them.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -