Java 为什么波托奇金';s EDT检查器是否标记此代码?

Java 为什么波托奇金';s EDT检查器是否标记此代码?,java,swing,user-interface,aspectj,event-dispatch-thread,Java,Swing,User Interface,Aspectj,Event Dispatch Thread,我不明白为什么我的代码在这个实例中被标记 myPlot.plot(serviceRef, frameMax, frameMin); 该行是错误的源位置。因为代码行中没有Swing代码,所以它对我来说没有任何意义。为什么会这样呢 我在下面附上了Potochkin的EDT违规检查代码: package testEDT; import javax.swing.*; /** * AspectJ code that checks for Swing component methods be

我不明白为什么我的代码在这个实例中被标记

myPlot.plot(serviceRef, frameMax, frameMin);
该行是错误的源位置。因为代码行中没有Swing代码,所以它对我来说没有任何意义。为什么会这样呢

我在下面附上了Potochkin的EDT违规检查代码:

    package testEDT;

import javax.swing.*;

/**
 * AspectJ code that checks for Swing component methods being executed OUTSIDE the Event-Dispatch-Thread.
 * 
 * (For info on why this is bad, see: http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html)
 * 
 * From Alexander Potochkin's blog post here:
 * http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
 * 
 */
aspect EdtRuleChecker{
    /** Flag for use */
    private boolean isStressChecking = true;

    /** defines any Swing method */
    public pointcut anySwingMethods(JComponent c):
         target(c) && call(* *(..));

    /** defines thread-safe methods */
    public pointcut threadSafeMethods():         
         call(* repaint(..)) || 
         call(* revalidate()) ||
         call(* invalidate()) ||
         call(* getListeners(..)) ||
         call(* add*Listener(..)) ||
         call(* remove*Listener(..));

    /** calls of any JComponent method, including subclasses */
    before(JComponent c): anySwingMethods(c) && 
                          !threadSafeMethods() &&
                          !within(EdtRuleChecker) {
        if ( !SwingUtilities.isEventDispatchThread() && (isStressChecking || c.isShowing())) {
            System.err.println(thisJoinPoint.getSourceLocation());
            System.err.println(thisJoinPoint.getSignature());
            System.err.println();
        }
    }

    /** calls of any JComponent constructor, including subclasses */
    before(): call(JComponent+.new(..)) {
        if (isStressChecking && !SwingUtilities.isEventDispatchThread()) {
            System.err.println(thisJoinPoint.getSourceLocation());
            System.err.println(thisJoinPoint.getSignature() + " *constructor*");
            System.err.println();
        }
    }
}

“myPlot”变量是扩展JPanel的AbstractPlot的实例!这会导致EDT检查器标记在此实例上进行的超出EDT的所有调用,即使我只是在计算一个int I=1+1的私有函数。现在我明白了:)

请格式化您的代码。这本身就是一个很大的违反:-)。也不明白,单个代码行和上午测试代码之间有什么联系。不知道,为了更好地帮助您,请尽快发布
JComponent
(或子类)方法在
plot
中被调用?啊,你把它钉死了!见下面我的答案:)