public class Utils
{
public static long getThreadId()
{
Thread t = Thread.currentThread();
return t.getId();
}
public static String getThreadSignature()
{
Thread t = Thread.currentThread();
long l = t.getId();
String name = t.getName();
long p = t.getPriority();
String gname = t.getThreadGroup().getName();
return (name
+ ":(id)" + l
+ ":(priority)" + p
+ ":(group)" + gname);
}
public static void logThreadSignature()
{
Log.d("ThreadUtils", getThreadSignature());
}
public static void sleepForInSecs(int secs)
{
try
{
Thread.sleep(secs * 1000);
}
catch(InterruptedException x)
{
throw new RuntimeException("interrupted",x);
}
}
}
satya - Friday, May 13, 2011 2:08:00 PM
A bit more useful version
I have added a "tag" so that I can now where this method is called from.
public class Utils {
public static long getThreadId()
{
Thread t = Thread.currentThread();
return t.getId();
}
public static String getThreadSignature()
{
Thread t = Thread.currentThread();
long l = t.getId();
String name = t.getName();
long p = t.getPriority();
String gname = t.getThreadGroup().getName();
return (name + ":(id)" + l + ":(priority)" + p
+ ":(group)" + gname);
}
public static void logThreadSignature(String tag)
{
Log.d(tag, getThreadSignature());
}
public static void sleepForInSecs(int secs)
{
try
{
Thread.sleep(secs * 1000);
}
catch(InterruptedException x)
{
throw new RuntimeException("interrupted",x);
}
}
}