흥미 롭습니다!
조건부 중단 점의 유무를 확인하기 위해 일부 소스 코드를 사용했습니다. 아래 첨부. 조건부 중단 점 디버거에서
실행 :
이 기간 : 1,210,623 마이크로
이 조건부 중단없이 디버거에서
실행 :
기간 : 24 마이크로
는 VM이 때문에 중단되지 IMHO 두 번째 스레드가 계속해서 나란히 실행됩니다. Eclipse는 현재 클래스에 중단 점 코드를 주입해야합니다. 어쩌면 모든 호출마다 그렇게 할 수 있으며 모든 호출에서 클래스를 다시 컴파일해야 할 수도 있습니다. Eclipse 소스를 확인하면 정확히 무슨 일이 일어나는지 알 수 있습니다.
C# 및 Visual Studio에서 조건부 중단 점을 실행 한 경험이 훨씬 더 나쁩니다. 위장감은 상황이 몇 가지 더 심각하다는 것입니다.
public class BreakPointPlay {
static int breakpointHits;
static volatile int modifiedBySecondThread;
static volatile boolean stopped;
public static void main(String[] args) throws InterruptedException {
Thread secondThread = startSecondThread();
final long LOOPS = 1000;
long counter = 0;
long start = System.nanoTime();
for (long i = 0; i < LOOPS; i++) {
// place breakpoint here and set the condition to the
// #breakPointCondition() method.
counter += i;
}
long stop = System.nanoTime();
long nanos = stop - start;
long micros = nanos/1000;
System.out.println("\nDuration: " + micros + " microseconds\n");
printInfo();
stopped = true;
secondThread.join();
}
private static Thread startSecondThread() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while(! stopped){
modifiedBySecondThread++;
}
}
});
thread.start();
return thread;
}
private static void printInfo() {
printModifiedBySecondThread();
printThread();
printClassLoader();
printStackTrace();
printModifiedBySecondThread();
}
private static void printStackTrace() {
Exception exception = new Exception();
exception.fillInStackTrace();
exception.printStackTrace(System.out);
}
private static void printModifiedBySecondThread() {
print("modifiedBySecondThread " + modifiedBySecondThread);
}
public static boolean breakPointCondition(){
breakpointHits++;
if(breakpointHits == 100){
printInfo();
}
return false;
}
private static void printClassLoader() {
print("ClassLoader " + new BreakPointPlay().getClass().getClassLoader());
}
private static void printThread() {
print("Thread " + Thread.currentThread());
}
private static void print(String msg){
System.out.println(msg);
}
}