Java Reference
In-Depth Information
public void run()
{
synchList.add(0, "Fuser1101");
}
public static void main(String[] args)
{
new ShowConcurrentMutex2().go();
}
}
It is important to synchronize on the right mutex object when cloning the underlying
collection. The synchronizedList() method creates an object that wraps the source
collection. This object synchronizes on itself when accessing to the source list. To clone
the source safely, you need to synchronize on this same object: the synchList object in
the program.
As before, this program prints out a valid list of "up" equipment. The difference is that now,
the second thread is not blocked while the primary thread iterates over its clone—a critical
distinction in practice!
Search WWH ::




Custom Search