0

この 1 つのインスタンスでコードにフラグが立てられる理由がわかりません。

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();
        }
    }
}
4

1 に答える 1

0

「myPlot」変数は、JPanel を拡張する AbstractPlot のインスタンスです。これにより、EDT チェッカーは、int i = 1 + 1 を実行するプライベート関数を計算しているだけであっても、EDT の外でこのインスタンスで行われたすべての呼び出しにフラグを立てます。これで理解できました :)

于 2012-10-25T15:25:45.807 に答える