设置了线程中断,中断标识不起效

设置了线程中断,中断标识不起效

功能要求:后台单独开一个线程启动一个长时间的耗时任务,支持中途中断

问题:在取消任务的请求逻辑中,通过interrupt()设置线程终止,然后在耗时任务通过isInterrupted()判断中断信息,然而isInterrupted()返回的一直是FALSE

异常:在后台日志中,看到有oracle驱动相关的异常

Caused by: java.io.InterruptedIOException: Socket read interrupted
	at oracle.net.nt.TimeoutSocketChannel.handleInterrupt(TimeoutSocketChannel.java:549)
	at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:420)
	at oracle.net.ns.NSProtocolNIO.doSocketRead(NSProtocolNIO.java:1119)
	at oracle.net.ns.NIOPacket.readHeader(NIOPacket.java:267)
	at oracle.net.ns.NIOPacket.readPacketFromSocketChannel(NIOPacket.java:199)
	at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:141)
	at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:114)
	at oracle.net.ns.NIONSDataChannel.readDataFromSocketChannel(NIONSDataChannel.java:98)
	at oracle.jdbc.driver.T4CMAREngineNIO.prepareForUnmarshall(T4CMAREngineNIO.java:834)
	at oracle.jdbc.driver.T4CMAREngineNIO.unmarshalUB1(T4CMAREngineNIO.java:487)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:622)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:299)
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:498)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:152)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:937)
	... 24 common frames omitted

猜测是否是由于oracle驱动使用Thread.interrupted()判断,一排查,发现确实是:

设置了线程中断,中断标识不起效

这里把中断标识清了,导致我后面判断一直不成功,最后我只想说:我服辣!

上一篇:ORACLE 表解锁


下一篇:【UJN-寒假练练练】新年快乐-2-进制转换与字符串_S - Number of letters