How to print name of the thread that enters a synchronized method
635127Apr 29 2008 — edited Apr 29 2008Hello,
I've a simple java program with multiple threads running. I also have the below synchronized method in my program.
public synchronized static int getReadIndex()
{
int currentIndex = readIndex;
readIndex = readIndex + chunkSize; //update readIndex to point to next chunk
return(currentIndex);
}
I want to generate some statistics and want to print the thread name and the corresponding index value whenever it enters the synchronized method.
Can anyone please tell me how to do that.
This is my thread class
private static class DatabaseThread extends Thread
{
public void run(){.....}
}
and this is how I create a thread object:
private static DatabaseThread myThread1 = new DatabaseThread();
Also, how do I specify thread name while creating the thread.
Thanks.