JCIP defines Guarded objects as:
Guarded. A guarded object can be accessed only with a specific lock held. Guarded objects include those that are encapsulated within
other thread-safe objects and published objects that are known to be guarded by a specific lock.
Which can be cited as an example of such an object inside core Java ?
What comes to my mind immediately is the list held by the
SynchronizedListinstance returned byCollections.synchronizedList(). Here’s a part of its source code:The
listobject is not thread safe, but is guarded by the mutex. The object returned bylistIterator()should be manually guarded by the same mutex (which is the synchronized list itself)