错在哪里?急急急急急急急急急急急急急急急急急急急急急急急急急

孙亖
博客专家认证
2004-07-30 11:25:16
public class test {

public static String muteObj = new String();

public static void main(String[] args) {

try {
AnotherThread at = new AnotherThread();
at.start();
System.out.println("before wait..." + Thread.currentThread().getClass().getName());
//statement 1
muteObj.wait();
System.out.println("after wait...");
} catch (Exception e) {
e.printStackTrace();
}
}
}

class AnotherThread implements Runnable {
public void start() {
new Thread(this).start();
}

public void run() {

try {
System.out.println("start another thread...");
Thread.sleep(10000);
System.out.println("end another thread...");
} catch (Exception e) {
} finally {
System.out.println("another thread finally");
test.muteObj.notify();
}
}
}

怎样才能让AnotherThread finally后再执行statement 1.谢了。
急急急急急急急急急急急急急急急急急急急急急急急急急
...全文
114 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
孙亖 2004-07-30
  • 打赏
  • 举报
回复
程序原来的做法就是那个样子的,如果改的话,变动太大了,我不想那样,还有其他办法吗?谢谢
maowu 2004-07-30
  • 打赏
  • 举报
回复
AnotherThread at = new AnotherThread();
Thread t = new Thread(at);
t.start();
t.join();
//这样不是很好好吗?
孙亖 2004-07-30
  • 打赏
  • 举报
回复
to bluesmile979(笑着) and maowu(猫呜)
非常感谢,可是我的at 是Runnable 而不是 Thread, 这该怎么办呢?
maowu 2004-07-30
  • 打赏
  • 举报
回复
Thread.currentThread().getClass().getName());
at.join();//加多这一行
//statement 1
bluesmile979 2004-07-30
  • 打赏
  • 举报
回复
public class test {

public static String muteObj = new String();

public static void main(String[] args) {

try {
AnotherThread at = new AnotherThread();
at.start();



at.join();










System.out.println("before wait..." + Thread.currentThread().getClass().getName());
//statement 1
muteObj.wait();
System.out.println("after wait...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
孙亖 2004-07-30
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/TopicView1.asp?id=3222720

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧