一條異常日志
[Error][.CinSocketHandlerThread][run][58][SYS_101][1000][433957346][5.1.1|LMY47V
release-keys|2017042817|5.2.25|SMARTISAN|YQ601][4|NETWORK_TYPE_LTE][]Socket添加任務隊列異常,errorMsg:java.lang.InterruptedException
at? java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1991)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2025)
atjava.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
atcom.allstar.cinclient.socket.CinSocketHandlerThread.run(:49)
代碼
LinkedBlockingQueue
@Override
public
voidrun()
{
CinClient.attachCurrentThreadUncatchExceptionHandler();
while(CinClient.isMainProcessRunning())
{
CinSocketTasktask
=null;
try
{
task =_queue.take();
if(task
!=null&&task.Trans!=null)
{
Trace.T(this.hashCode());
task.Trans.receiveResponse(task.Response);
}
}
catch(InterruptedExceptione)
{
LogOpr.error("Socket添加任務隊列異常,errorMsg:"+Log.getStackTraceString(e),ErrorCode.SYS_TCP,"",LogOpr.getFileName(),LogOpr.getMethodName(),LogOpr.getLineNumber());
}
catch(Exceptione)
{
LogOpr.error("Socket添加任務隊列異常,errorMsg:"+Log.getStackTraceString(e),ErrorCode.SYS_TCP,"",LogOpr.getFileName(),LogOpr.getMethodName(),LogOpr.getLineNumber());
}
}
System.out.println("----------Task
STOP!!------");
}
產生異常的源頭
CinSocketHandlerThreadPool.java
//logon時調用
public static voidinitialize(intlength){
if(_threads!=null){
stop();
}
_threads=newCinSocketHandlerThread[length];
for(inti=0;i<
length;i++){
_threads[i] =newCinSocketHandlerThread();
_threads[i].start();
}
}
public static voidstop(){
for(Thread t :_threads){
t.interrupt();
}
}
app異常現象:每次登陸,都會泄露5個CinSocketHandlerThread線程,該線程是用來處理網絡響應的
延伸:什么時候,線程會中斷
1.線程在運行中,不會中斷,如果其他線程調用了該線程的interrupt方法,只是對該線程的interrupt標志位置位,該線程能通過
Thread.currentThread().isInterrupted()來訪問該標志。
2.如果該線程在執行一個低級可中斷阻塞方法,例如 Thread.sleep()、
Thread.join() 或
Object.wait(),那么它將取消阻塞并拋出
InterruptedException。
3.并非所有的阻塞方法都拋出?InterruptedException。輸入和輸出流類會阻塞等待 I/O 完成,但是它們不拋出InterruptedException,而且在被中斷的情況下也不會提前返回。