前言:监控线程
/**
* 说明:线程监控工具类
* 作者:黄伟财
* 日期:2016-2-4
*/
public class TreadUtils {
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 getLogThreadSignature(){
Log.d("TAG", getThreadSignature());
}
//控制当前线程睡眠
public static void sleepForInSecs(int secs){
try {
Thread.sleep(secs * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//如下两个方法执行在工作线程,后面介绍
public static Bundle getStringAsBundle(String message){
Bundle b = new Bundle();
b.putString("message", message);
return b;
}
public static String getStringFromABundle(Bundle b){
return b.getString("message");
}
}