3
현재 Alexander Potochkin의 AspectJ EDTChecker code (게시물 하단의 관련 코드)을 사용하고 있습니다.AspectJ EDT-Checker 코드 질문
이 코드는 JComponent 메서드 호출이나 Swing EDT 내에서 발생하지 않는 생성자 호출에 대해 불만을 토로합니다.
그러나 다음은 JFrame 생성자가 아니라 JList 생성자에만 불만을 표시합니다. 아무도 그 이유를 말할 수 있습니까? 감사!
package testEDT;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
public class TestEDT{
JList list;
final JFrame frame;
public TestEDT() {
DefaultListModel dlm = new DefaultListModel();
list = new JList(dlm);
frame = new JFrame("TestEDT");
}
public static void main(String args[]) {
TestEDT t = new TestEDT();
t.frame.setVisible(true);
}
}
알렉산더 Potochkin의 AspectJ를 코드 :
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();
}
}
}
와우. 충분히 공정하다. 나는 몰랐다. 나는 허용 될 때이 대답을 받아 들일 것이다. – BenCole