Take some straight lines:
- The synchronized block monitor is actually an object monitor
- Links to the monitor are synchronized: do you need all the places in the code that this monitor refers to, or all the fields / local variables pointing to the monitor?
Where in the code referenced by the monitor?
Suraj already describes how to do this: Search > References > Workspace... You can also filter these links only for read access, write access, implementation, etc. Such links can be found as a result of static code analysis, so there is no need to run the application. This, however, will not automatically detect cases where an object reference is assigned to a field, which is then assigned to another variable. This only defines a link to that particular object link.
What variables indicate the monitor?
This will handle the case when multiple fields / local variables refer to an object. For this, the application must work. You need to put a breakpoint in the right place where the monitor is displayed (the easiest way is somewhere near the synchronized block that this monitor uses). The Variables view will show all the variables available in the current area. You can get all references to an object by selecting the link to the object in the Variables view, entering the context menu and selecting All References... This will show you all the fields / local variables that reference the object.
Danail nachev
source share