Hello all i have done java application that invoking some stuff this application is multithread now i like to print to log every time some application has invoked my application api the current thread id , so then i could grep in logs the flow by thread id . how can it be done in java to get the current thread id ?
Thread object for current thread is Thread.currentThread(), a static method.
From Java 5 onwards, there is a Thread instance method getId(). Before that, there is only getName().
The getId() method may, or may not, return the underlying operating system (OS) thread ID. Remember that Java threads are not required to have a one-to-one correspondence with OS threads; they usually do, but it's not guaranteed. If you find that getId() does give the OS thread ID on your favourite JVM and OS, that's fine to an extent, but making that assumption makes your program non-portable.
Finally, note that the value returned by getId() can be the same for two different threads. This is because, while the ID of a thread will not change while it is running, and no other thread will have the same ID while it is running, the ID may be reused when it terminates. Generally, the ID will not be reused for a long time, but making that assumption is again non-portable. [ June 25, 2007: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.