you can use CountDownLatch . it is a important concurrent tool class . if you want know more about java multithreaded program . see the book Java Concurrency in Practice [Brian Goetz]
int i = 0;
List<Customer>customers = customer.getCustomers();
CountDownLatch cdl =new CountDownLatch(customers.size()); // new code
long startTimestamp = System.currentTimeMillis();
for (Customer c: customers){
new RequestProcessor(cdl,c, i).start();
i++;
}
cdl.await(); // new code .
// the thread will hang up unitl all RequestProcessor run cdl.countDown() ;
long endTimestamp = System.currentTimeMillis();
System.out.println("difference = "+(endTimestamp - startTimestamp));
RequestProcessor.class
public RequestProcessor(CountDownLatch cdl, Customer customer , int threadSeq ) {
super();
this.customer = customer;
this.threadSeq = threadSeq;
this.cdl=cdl; // new code
}
@Override
public void run() {
// TODO Auto-generated method stub
processRequest();
super.run();
cdl.countDown(); // new code
}