As mentioned above the dataqueue read timeout is server side. If the TCP connection between the iSeries and the client stalls or dies the client will wait until the socket times out. My solution is to institute a fail safe interrupter to stop a stalled read. Here is a quick code sample of how this can be done.
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 strongly recommend recreating the DataQueue object on a new AS400 connection after an InterruptedException. Chances are that your AS400 connection is stalled. Thread.interrupt is very useful, but use it with caution.