0
ArrayBlockingQueue
을 사용하여이 생산자 - 소비자 코드를 고려하십시오. a를 찾고 싶습니다. 전반적인 시간은 put()
/take()
전체적으로 소모됩니까? b. 기다리는 중 put()
및 take()
통화가 얼마나 많은 총 시간을 소비 했습니까? 차단 되었습니까?Java 응용 프로그램 프로파일 링 : 재귀 적으로 메소드의 누적 시간
VisualVM에서 스냅 샷을 찍을 때 실행 깊이()는 표시되지만 put()
/take()
호출은 표시되지 않습니다. 이 시간을 얻는 방법에 대한 아이디어?
일반적으로 모든 메서드의 누적 실행 시간은 main()
에서 재귀 적으로 어떻게 계산합니까?
final BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(QUEUE_SIZE);
ExecutorService exec = Executors.newFixedThreadPool(2);
exec.submit(new Runnable() {
int i =0;
@Override
public void run() {
while(i++<NUM)
try {
queue.put(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
exec.submit(new Runnable() {
int i =0;
@Override
public void run() {
while(i++<NUM)
try {
queue.take();
} catch (InterruptedException e) {
e.printStackTrace();
}
consumerFinished.countDown();
}
});