Red*_*gle 6 java http jtopen ibm-midrange
当我使用JTOpen KeyedDataQueue类提供的read()方法时,我发现了一个奇怪的行为.
当达到超时时,我设置了90秒的超时和99%的读取执行,我的调用方法执行恢复.
至于其他1%,超时未被考虑/达到,我的呼叫方法保持挂起...
搜索了一下后我发现这篇文章:
http://archive.midrange.com/java400-l/201112/msg00056.html
基本上它证实了我的怀疑:
"我还发现DataQueue.read()超时功能是服务器端的,所以如果TCP/IP连接被静默拆除(我认为这是导致此问题的根本原因),它仍然会挂起."
我正在使用JTOpen的7.2版,我意识到版本7.9已经存在.我没有更新到7.9,因为我有很多使用7.2的关键应用程序是稳定的,这真的是第一个让我考虑更新到7.9的真实场景.
为了帮助我做出这个决定,我非常希望得到您的反馈,尤其是那些遇到这种情况并最终通过升级JTOpen解决它的人.
具体来说,是否存在此问题的解决方法,并且升级JTOpen对此有何帮助?将JTOpen升级到7.9会破坏7.2中的任何工作吗?
如上所述,数据队列读取超时是服务器端的。如果 iSeries 和客户端之间的 TCP 连接停止或终止,客户端将等待,直到套接字超时。我的解决方案是建立一个故障安全中断器来停止停滞的读取。以下是如何完成此操作的快速代码示例。
public class DataQueueListenerExample {
//This executes our Interrupter after the specified delay.
public final ScheduledThreadPoolExecutor interruptExecuter = new ScheduledThreadPoolExecutor(1);
//the dataqueue object.
protected DataQueue dataqueue;
public DataQueueEntry read(int wait)
{
ScheduledFuture<?> future = null;
try {
//create our fail safe interrupter. We only want it to
//interrupt when we are sure the read has stalled. My wait time is 15 seconds
future = createInterrupter(wait * 2, TimeUnit.SECONDS);
//read the dataqueue
return this.dataqueue.read(wait);
} catch (AS400SecurityException e) {
} catch (ErrorCompletingRequestException e) {
} catch (IOException e) {
} catch (IllegalObjectTypeException e) {
} catch (InterruptedException e) {
//The read was interrupted by our Interrupter
return null;
} catch (ObjectDoesNotExistException e) {
} finally{
//Cancel our interrupter
if(future != null && !future.isDone())
future.cancel(true);
Thread.interrupted();//clear the interrupted flag
interruptExecuter.shutdown();
}
return null;
}
public ScheduledFuture<?> createInterrupter(long timeout,TimeUnit timeunit)
{
return interruptExecuter.schedule(new Interrupter(),timeout,timeunit);
}
class Interrupter implements Runnable
{
final Thread parent;
Interrupter()
{
this.parent = Thread.currentThread();
}
@Override
public void run() {
parent.interrupt();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我强烈建议在 InterruptedException 发生后在新的 AS400 连接上重新创建 DataQueue 对象。您的 AS400 连接很可能已停止。Thread.interrupt 非常有用,但要谨慎使用。
| 归档时间: |
|
| 查看次数: |
626 次 |
| 最近记录: |