如何判断一个线程是否在运行中? 如何判断一个线程是否在运行中?我现在有很多个线程在一起跑,但我不知道哪个线程已经推出了run函数,怎么判断? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一般写线程的时候,我都会定义一个boolean stopped变量,在run的while循环里使用这个变量来判断是否继续执行循环中的语句:public void run() { while (!stopped) { // code........ } stopped = true;} public final boolean isAlive() Tests if this thread is alive. A thread is alive if it has been started and has not yet died. 用 isAlive()方法 if(thread1.isAlive()){ System.out.println("thread1 is alive");}else{System.out.println("thread2 is not alive");} ConcurrentHashmap使用 PipedOutput(Input)Stream传递非byte类型数据 Applet Java里对文件操作,求助! 新手的问题 请教,关键字:MSSQL 存储过程 多数据集 可滚动。 关于Frame的问题 ★★★公告:J2SE/基础类招收斑竹!!★★★ java 高手请进 请问那儿有璩美鳳偷拍光碟下载!!有效给分!! 如何避免使用静态方法? eclipse中添加了struts和hibernate 但是在写配置文件时没有提示??
while (!stopped) {
// code........
}
stopped = true;
}
if(thread1.isAlive()){
System.out.println("thread1 is alive");
}
else
{
System.out.println("thread2 is not alive");
}