How can I find all synchronized on the same monitor in Java with Eclipse?

With Eclipse it is possible to find all references of a method, member or class. Is it also possible to find all references to the monitor of a synchronized?

If this is not possible with Eclipse then is it possible with another Java IDE?

My problem is that the monitor object hat many references. A search for all references will return to many results. I will only see where are synchronized with this object.

EDIT: I add a sample what i means:

public class LockClass{
  public synchronized void add(Object any){
  }
}

public class AnyOther{
  private LockClass lock;

  public AnyOther(LockClass lock){
    this.lock = lock;
  }

  public void doSomethings(){
    synchronized(lock){
      //...
    }
}

Now I want search all synchronized which use the LockClass as monitor. This is a static analyses. In my sample I want find:

  • LockClass.add
  • AnyOther.doSomethigs

  • Let's get some terms straight:

  • The monitor of a synchronized block is in fact the monitor on an object
  • References to the monitor of a synchronized is ambigous: do you want all places in the code where this monitor is referenced or all fields/local variables which points to the monitor?
  • Where in the code the monitor is referenced?

    Suraj already describe how to do this: Search > References > Workspace... . You can also filter those references to only read access, write access, implementators, etc. Such references are found through static code analysis, so no need to run the application. This, however, will not automatically detect the cases where a reference to an object is assigned to a field, which is then assigned to another variable. This only detects reference to this particular reference to the object.

    Which variables points the monitor?

    This will handle the case when several fields/local variables reference the object. To do this, the application must be running. You need to put breakpoint in a proper place, where the monitor is visible (the easiest way is somewhere around a synchronized block, which use the monitor in question). The Variables view will show all variables available in the current scope. You can get all references to an object by selecting an reference to the object in the Variables view, bringing the context menu and selecting All References... . This will show you all fields/local variables, which reference the object.


    To find references: Select your element->rt-click menu->References->workspace

    Its not possible to find all possible synchronized blocks on the same object, because the actual object pointed by a reference would depend at runtime.


    Eclipse will not be able to find references to a certain object. It can only find references to a certain symbol, eg a variable, a class, a method aso A monitor can be this or the value of a variable o -- both pointing to the same object at run-time. However, Eclipse has no way to extract run-time information like that.

    链接地址: http://www.djcxy.com/p/53340.html

    上一篇: 如何在Linux上编译ASL(基于boost的Adobe C ++ gui库)?

    下一篇: 如何在Java中使用Eclipse在同一监视器上查找所有同步?