public class TestRunnable implements Runnable{
@Override
public void run() {
System.out.println("我实现了Runnable接口");
}
public static void main(String[] args) throws InterruptedException{
TestRunnable tr=new TestRunnable();
ThreadGroup tg=new ThreadGroup("线程组1");
Thread tt=new Thread(tg,tr,"线程1");
tt.start();
tt.sleep(2000);
//优先级
int priority=tt.getPriority();
//名称
String name=tt.getName();
//id
long id=tt.getId();
System.out.println("此线程的优先级是"+priority+" 此线程的名称"+name+" 此线程的id"+id);
//栈追踪元
StackTraceElement[] arr=tt.getStackTrace();
for(StackTraceElement ele:arr){
String eleClassName=ele.getClassName();
String FileName=ele.getFileName();
int lineNumber=ele.getLineNumber();
String eleMethodName=ele.getMethodName();
System.out.println("栈追踪元eleClassName="+eleClassName+" FileName"+FileName
+" lineNumber="+lineNumber+" eleMethodName"+eleMethodName);
}
//所属线程组
ThreadGroup group= tt.getThreadGroup();
if(group!=null){
int maxPriority=group.getMaxPriority();
String groupName=group.getName();
System.out.println("最大优先级"+maxPriority+" groupName"+groupName);
}
}
}