I am reading the book Java Concurrency in Practice.
In Chapter 4.2 – Instance Confinement it says Confined objects can also escape by publishing others such as iterators or innerclass instances that may indirectly publish the confined objects.
Can someone give an example (code) on each please ?
I am reading the book Java Concurrency in Practice . In Chapter 4.2 –
Share
Sure, here are two examples.
Iterator:
Even though
xis private, you can still perform operations, such asdelete(), on itsIterator, modifyingx.Inner class:
Here, an escaped reference to
Inner, causes an indirect reference toxto leak out, even though it is private.