首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JTOpen KeyedDataQueue read()超时值

JTOpen KeyedDataQueue read()超时值
EN

Stack Overflow用户
提问于 2013-05-01 11:46:46
回答 1查看 826关注 0票数 6

在使用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中起作用的东西吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-08 15:59:11

如前所述,dataqueue读取超时是服务器端。如果iSeries与客户端之间的TCP连接中断或死亡,则客户端将等待套接字超时。我的解决方案是建立一个故障安全中断器,以阻止一个停滞的阅读。下面是一个简单的代码示例,说明如何做到这一点。

代码语言:javascript
复制
    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();
        }
    }
    }

我强烈建议在DataQueue之后在新的AS400连接上重新创建InterruptedException对象。很可能您的AS400连接被中断了。Thread.interrupt非常有用,但要谨慎使用它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16317554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档