I have encountered a problem when I want to do a time counting.
Basicly the problem is like this: there is a class A, which initiates a private thread in itself, and I have a instant of A in my class B, and in the main method of B I invoked some methods of A and want to test the time to run these methods.

A a = new A();
//start time counter
for (int i = 0; i < 10; i++){ invoke a.method() that takes some time}
//end time counter and prints the time elapsed

but by doing so the method in the for loop will running in a seperate thread in A and the prints method in the last line would probably be executed before the loop ends. So I want to access the thead in a and invokes a join() to wait until all stuff in the for loop get finished. Could you help me figure how to achieve this? Any ideas would be greatly appreciated.

I want to try Thread.currentThread(), but the A class is a third party class that could not be modified.
–
Arrow CenJun 20 '11 at 18:08

Is it possible that A exposes some threading functionality in its public interface ? I'm thinking of allowing you to join() its inner thread, for instance (without actually exposing its thread reference). Or does it perform some notify() on the A instance when finished (so that you can wait() on it) ?
–
Costi CiudatuJun 20 '11 at 18:16

Hi Costi, in fact A is the AsyncAppender in log4j, and I configure it in a .xml file, all I have in my program is a Logger that has already append that appender a. I do not have access to any reference to the appender itself. Even though I can get one reference by invoking getAppender() on the Logger, there is no public interface availabel for the appender to access the thread. Any way thanks for your help
–
Arrow CenJun 20 '11 at 18:44