我必须执行2种方法线程:执行具有螺纹完整方法中,一旦方法的执行完成启动另一个方法
await()
signal()
的条件是完成执行之后的方法await()
,那么只应该调用方法signal()
。
在我的情况下,应用程序正在关闭。
我在这里写的样本例如:
private final Object lock = new Object();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
signal();
try {
await();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Method: after await");
}
public void signal() {
synchronized (lock) {
System.out.println("Method before ");
**lock.notify();**
System.out.println("Method await after signal ");
}
}
public void await() throws InterruptedException {
// synchronized (lock) {
Thread t = new Thread() {
public void run() {
System.out.println("Method await before wait ");
try {
**lock.wait();**
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("Method in exception ");
}
System.out.println("Method await after wait ");
}
};
}
'请提供解决方案'是不是什么SO。如果你有一个特定的问题,你不能自己解决,尽管我们很乐意帮助你。 – Keppil 2012-07-26 07:14:59
我喜欢你的评论Keppil,我为此尝试了很多,但总是得到InterruptedException异常,我通过创建两个不同的类来解决这个问题,但是我需要一些关于我在这里发布的相同逻辑的帮助,如果你可以帮助解决它的可观性。谢谢 – dhir 2012-07-26 07:23:16