JTOpen KeyedDataQueue read () timeout

I found strange behavior when using the read () method provided by the JTOpen KeyedDataQueue class.

I set a timeout of 90 s and 99% of the read completion, when the timeout is reached, my call method execution resumes.

As for the remaining 1%, the wait time is not counted / reached, and my call method remains cherry ...

After some searching, I found this message:

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

This basically confirms what I suspected:

"I also found that the ServerQuest timeout function DataQueue.read () was on the server side, so if the TCP / IP connection is quietly disconnecting (which I believe is the main reason for this), it will still hang."

I am using version 7.2 of JTOpen and I understand that version 7.9 already exists. I have not upgraded to 7.9 because I have many critical applications with 7.2 that are stable and this is really the first real scenario that forces me to consider upgrading to 7.9.

To help me in this decision, I would really like your feedback, especially from those of you who have encountered this situation and ultimately resolved it by updating JTOpen.

In particular, are there any workarounds for this issue, and does JTOpen help update? Will updating JTOpen to 7.9 break everything that works in 7.2?

+6
source share
1 answer

As mentioned above, the data read timeout is server side. If the TCP connection between the iSeries and the client stops or dies, the client will wait until the socket fails. My solution is to create a safe interrupter to stop a locked reading. Here is an example quick code on how to do this.

  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(); } } } 

I highly recommend re-creating the DataQueue object on the new AS400 connection after InterruptedException. Most likely your AS400 connection has stalled. Thread.interrupt is very useful, but use it with caution.

+1
source

Source: https://habr.com/ru/post/944033/


All Articles