0

In Java, Hashtable has individual methods synchronized and not the table instance variable. That means a put and a putIfAbsent(or remove) can still run in parallel, right ?

This means one should use other synchronization options for absolute thread safety or write safety using Collections.synchronizedMap(object-mutex level synchronization) or ConcurrentHashMap(segment level synchronization) !

If so we should not simply say that Hashtable is threadsafe. Isn't it ?

1 Answers1

1

I think you misunderstand what it means to declare a method 'synchronized'. Such methods are synchronized on the object instance, so that only one can execute at a time on that particular object instance.

user16632363
  • 1,050
  • 3
  • 6