총 내 프로그램에서 작성한 모든 스레드를 계산하려고하는데 내 코드는 호출 시간 만 계산합니다. 출력에 난 모든 스레드가 내 멀티 스레드 프로그램의 실행 시간을 계산하는 방법
아래에있는 내 주요 프로그램 RequestProcessor가 여기 내 스레드 클래스 아래
int i = 0;
List<Customer>customers = customer.getCustomers();
long startTimestamp = System.currentTimeMillis();
for (Customer c: customers){
new RequestProcessor(c, i).start();
i++;
}
long endTimestamp = System.currentTimeMillis();
System.out.println("difference = "+(endTimestamp - startTimestamp));
입니다
를 완료하기 전에 차이가 인쇄 참조 요청 프로세서 클래스 때문에나는 확신 아래
public RequestProcessor(Customer customer , int threadSeq) {
super();
this.customer = customer;
this.threadSeq = threadSeq;
}
@Override
public void run() {
// TODO Auto-generated method stub
processRequest();
super.run();
}
public void processRequest(){
//performing execution on customer here
System.out.println("processing "+ customer.getName()+" thread seq "+threadSeq);
}
내가
를 받고 오전 출력입니다processing customer9 thread seq 9
processing customer7 thread seq 7
difference = 4
processing customer3 thread seq 3
processing customer2 thread seq 2
나는 조인을 사용하려했지만 스레드의 특정 번호는 다음 실행 시간을 인쇄 할 수 있습니다 지적하는 countDown()
를 호출 할 때까지 기다려야하는 CountDownLatch
을 사용할 수 있습니다