Synchronization in Vectors in Java

前端 未结 4 991
独厮守ぢ
独厮守ぢ 2021-01-04 21:08

what is meant by vector in Java is thread safe and synchronized, how is it made thread safe. I\'m looking at internal details of implementation

4条回答
  •  囚心锁ツ
    2021-01-04 21:27

    Please find the below excerpts from java api

    First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.

    Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.

提交回复
热议问题