0
我不明白爲什麼我的代碼在這個實例中被標記。爲什麼Potochkin的EDT檢查器會標記此代碼?
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();
}
}
}
請格式化您的代碼。這是一個很大的違規:-)。 –
也不明白,單行代碼行與我的測試代碼之間有什麼聯繫,不知道,爲了更好的幫助,儘快發佈[SSCCE](http://sscce.org/) – mKorbel
什麼'JComponent'(或子類)方法在'plot'中調用? – trashgod