eguid/easyCV

非正常情况导致读流出错,从而影响线程计数,如rtsp流异常关闭会导致线程不可用

yuxb opened this issue · 1 comments

yuxb commented

大神你好,mainloop 方法里面貌似存在问题,当抓流器不能正常访问到rtsp流时, 方法进入catch 模块, 状态会被置为 STOP_STATUS 停止状态,线程的下一次for 循环会根据 status 状态让线程 执行wait(),线程进入等候状态,而此时当前线程所对应的task 并没有从workpool 移动到idlepool 中, 导致计数不对,当线程耗尽则 无法开启新的任务。

`/**
* 核心转换处理循环
*/
private void mainLoop() {
long startime=System.currentTimeMillis();
long err_index = 0;//采集或推流失败次数
long frame_index=0;
int pause_num=0;//暂停次数
try {
for(;status==START_STATUS;frame_index++) {
Frame pkt=grabber.grabFrame();
if(pause==1) {//暂停状态
pause_num++;
continue;
}
if(pkt==null) {//采集空包结束
if(err_index>err_stop_num) {//超过三次则终止录制
System.err.println(getName()+"工作线程采集视频帧连续"+err_index+"次空包,本次任务终止");
break;
}
err_index++;
continue;
}
record.record(pkt);
}
}catch (Exception e) {//推流失败
status=STOP_STATUS;//到这里表示已经停止了
System.err.println("异常导致停止录像,详情:"+e.getMessage());
}finally {

		//此处没有对线程池中的workpool 池中的任务移动到idepool中,导致计数错误
		status=STOP_STATUS;
		stopRecord();
		System.out.println(getName()+"工作线程的录像任务已结束,持续时长:"+(System.currentTimeMillis()-startime)/1000+"秒,共录制:"+frame_index+"帧,遇到的错误数:"+err_index+",录制期间共暂停次数:"+pause_num);
	}
}

exception 后 下一次for循环 线程进入等候状态,没有对线程池中的workpool 池中的任务移动到idepool中,导致计数错误

`@Override
public void run() {
go();
for(;;) {
if(status==2) {
System.out.println("工作线程进入等待状态");
synchronized (this){
try {
wait();
}catch(InterruptedException e) {
}
}
System.out.println("工作线程唤醒");
continue;
}
//核心任务循环
mainLoop();
}
}

//exception 后 下一次for循环 线程进入等候状态,没有对线程池中的workpool 池中的任务移动到
//idepool中,导致计数错误

@OverRide
public void run() {
go();
for(;;) {
if(status==2) {
System.out.println("工作线程进入等待状态");
synchronized (this){
try {
wait();
}catch(InterruptedException e) {
}
}
System.out.println("工作线程唤醒");
continue;
}
//核心任务循环
mainLoop();
}
}`

eguid commented

感谢反馈,确实存在这个问题,我会在保活定时器中回收已经停止的工作线程