The questions says it all, just wondering, in an interview, what would you say when they ask you, "What does it practically mean by Hashtable or Vectors being synchronized?"
HashMap is non-synchronized. It is not thread-safe and can't be shared between many threads without proper synchronization code whereas Hashtable is synchronized. It is thread-safe and can be shared with many threads.
Synchronization: Vector is synchronized, which means only one thread at a time can access the code, while ArrayList is not synchronized, which means multiple threads can work on ArrayList at the same time.
Hashtable methods are synchronized, but that only provides method-level protection against race conditions. (So a Hashtable —unlike a HashMap —will not become internally corrupted if multiple threads are concurrently trying to modify the data.) It is only in this sense that Hashtable is thread-safe.
Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads.
Practically it means two things:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With