-
package com.vtc365.codec;
-
-
import com.vtc365.utils.ConfigureHelper;
-
-
public abstract class EncoderThread extends Thread {
-
static int STOP=0;
-
static int RUNNING=1;
-
static int PAUSE=2;
-
Integer status=STOP;
-
public void run(){
-
status=RUNNING;
-
while(true){
-
synchronized (status) {
-
if(status==STOP)
-
break;
-
}
-
try {
-
Thread.sleep(5000);
-
} catch (InterruptedException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
}
-
}
-
}
-
-
public void stopThread(){
-
synchronized (status) {
-
status=STOP;
-
status.notify();
-
}
-
}
-
}
当调用该类的stopThread方法时,系统会在notify报错,object not locked by thread before notify();
百思不得其解,27行已经lock了啊。
仔细分析发现,27行的status,和29行的status已经不是一个对象了。
阅读(18600) | 评论(0) | 转发(0) |