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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -