gpt4 book ai didi

java - JTOpen KeyedDataQueue 读取()超时

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:33:07 26 4
gpt4 key购买 nike

在使用 JTOpen 的 KeyedDataQueue 类提供的 read() 方法时,我检测到一个奇怪的行为。

我设置了一个 90 秒的超时,当达到超时时,我的调用方法执行将恢复 99% 的读取执行。

至于另外 1% 的超时未被考虑/达到,我的调用方法保持挂起...

经过一番搜索,我找到了这篇文章:

http://archive.midrange.com/java400-l/201112/msg00056.html

基本上它证实了我的怀疑:

"I also found that the DataQueue.read() timeout functionality is server side so if the TCP/IP connection is silently torn down (which I believe is the underlying cause of this) it will still hang. "

我正在使用 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();
}
}
}

我强烈建议在出现 InterruptedException 后在新的 AS400 连接上重新创建 DataQueue 对象。您的 AS400 连接可能已停止。Thread.interrupt 非常有用,但要谨慎使用。

关于java - JTOpen KeyedDataQueue 读取()超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16317554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com