private static boolean isThread(){
try{
boolean isThread=false;
for (StackTraceElement i:Thread.currentThread().getStackTrace()){
if ((i.toString()).contains("xxxx")) {
isThread=true;
}
}
return isThread;
}catch (Exception e){
return false;
}
}
//z这个快一点
private static boolean isThread(){
try{
boolean isThread=false;
Exception exception = new Exception();
if(trace != null && trace.length > 2){
if (((exception.getStackTrace()[2]).toString()).contains("xxxx")) {
isThread=true;
}
}
return isThread;
}catch (Exception e){
return false;
}
}
判断调用者堆栈
于 2023-08-10 17:42:54 首次发布