ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexIBM MQ Java / JMSHow to give thread time out in MQ Java API

Post new topicReply to topic
How to give thread time out in MQ Java API View previous topic :: View next topic
Author Message
abhay09
PostPosted: Wed Dec 20, 2017 6:10 am Post subject: How to give thread time out in MQ Java API Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

Hi Guys,

I have an application that uses MQ Java API to connect to MQ and perform operations like get/put/access.

In my testing to simulate unstable network, I've added a network simulator between my application and MQ server to block the connection to MQ.
using sudo /sbin/iptables -I INPUT -s $hst -j DROP

It will drop the packets sent from my application to MQ.
I Understood that packets are dropped so there will be no response for that call but my threads are getting stuck.

In this scenario, I am getting so many stuck threads from IBM API.

Like :
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at com.ibm.mq.jmqi.remote.impl.RemoteSession.receiveAsyncTsh(RemoteSession.java:591)
- locked <0x00000007b70474a8> (a com.ibm.mq.jmqi.remote.impl.RemoteSession$AsyncTshLock)
at com.ibm.mq.jmqi.remote.impl.RemoteSession.receiveTSH(RemoteSession.java:804)
at com.ibm.mq.jmqi.remote.impl.RemoteSession.receiveMQIFlow(RemoteSession.java:1438)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiPutMessageWithProps(RemoteFAP.java:9072)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.MQPUT(RemoteFAP.java:8001)
at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.MQPUT(InterceptedJmqiImpl.java:679)
at com.ibm.mq.ese.jmqi.ESEJMQI.MQPUT(ESEJMQI.java:493)
at com.ibm.mq.MQDestination.internalMQPUT(MQDestination.java:1332)
- locked <0x00000007b70ec4b8> (a com.ibm.mq.MQQueue)
at com.ibm.mq.MQDestination.put(MQDestination.java:1187)
- locked <0x000000078d54f2b8> (a com.ibm.mq.MQMessage)





Now, how to handle such cases? Does MQ JAva API provides any method to add timeout to threads?

How can I time out these threads to prevent stuck threads? I know, because of simulator packets are dropped and there will be no response but my application should not hang (stuck threads) in between.

Please let me know how can I handle these situation when application runs in unstable network.


Many Thanks!
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Dec 20, 2017 8:41 am Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19770
Location: LI,NY

If you are doing an asynchronous read (or call back) you should also use a connection monitor (ExceptionListener) to be notified when the connection drops, cleanly remove the MQ resources and reacquire them.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
abhay09
PostPosted: Wed Dec 20, 2017 8:58 am Post subject: Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

fjb_saper wrote:
If you are doing an asynchronous read (or call back) you should also use a connection monitor (ExceptionListener) to be notified when the connection drops, cleanly remove the MQ resources and reacquire them.



My application is not getting any exception as connection is not dropped. It just that packets sent by my application to MQ is eaten by network simulator and my application (IBM APIs) is waiting for the response.

Do you know how can we gve timeout to mq connection or access queue API?
Back to top
View user's profile Send private message
tczielke
PostPosted: Wed Dec 20, 2017 12:06 pm Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 743
Location: Illinois, USA

This MQ manual link talks about how to set this:

https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q119470_.htm

For example:
java -Dcom.ibm.mq.cfg.TCP.Connect_Timeout=15 myJavaApp
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Dec 21, 2017 5:54 am Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19770
Location: LI,NY

tczielke wrote:
This MQ manual link talks about how to set this:

https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q119470_.htm

For example:
java -Dcom.ibm.mq.cfg.TCP.Connect_Timeout=15 myJavaApp


And here I thought you'd really need this in combination of TCP Keep_Alive...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tczielke
PostPosted: Thu Dec 21, 2017 3:23 pm Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 743
Location: Illinois, USA

Yes, this is a handy feature.

On Linux when you run something like the following:

java -Dcom.ibm.mq.cfg.TCP.Connect_Timeout=15 MQSamplePut

the underlying TCP connect call is performed with a non-blocking socket followed by a poll command that waits 15 seconds.

Code:

[pid  9646] fcntl(19, F_GETFL)          = 0x2 (flags O_RDWR)
[pid  9646] fcntl(19, F_SETFL, O_RDWR|O_NONBLOCK) = 0
[pid  9646] connect(19, {sa_family=AF_INET, sin_port=htons(1414), sin_addr=inet_addr("10.10.10.10")}, 16) = -1 EINPROGRESS (Operation now in progress)
[pid  9646] poll([{fd=19, events=POLLOUT}], 1, 14994) = 1 ([{fd=19, revents=POLLOUT}])


14994 above is roughly 15000 milliseconds.
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
abhay09
PostPosted: Tue Dec 26, 2017 10:52 pm Post subject: Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

Thanks Guys,

I tried with "-Dcom.ibm.mq.cfg.MQRCVBLKTO=15 -Dcom.ibm.mq.cfg.TCP.Connect_Timeout=15

and it worked for me. No more stuck threads on MQ API. and mq java api throwing 2009 exception for no response.


Thanks!
Back to top
View user's profile Send private message
abhay09
PostPosted: Tue Dec 26, 2017 11:00 pm Post subject: How to handle MQ API under network delay of 5 seconds Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

Hi Guys,

I have an application that uses MQ Java API to connect to MQ and perform operations like get/put/access.

MQ server/client jars: 8

In my testing to simulate slow network, I've added a network simulator between my application and MQ server to add a network delay of 5 seconds.
Command:
sudo -S /sbin/tc qdisc add dev eth0 root netem delay 5000ms

This command will delay every request to MQ server by 5 seconds.

Now in my testing, I am getting 2537, channle not available.

com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2537'.
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:250)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:97)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:868)
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:816)
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:758)
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:200)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:910)



I've gone through the docs, it means firewall is blocking or max connection limit.

Please let me know how to handle this with a network delay of 5 seconds.
How can we handle this situation in slow network.


Many Thanks!
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Java / JMSHow to give thread time out in MQ Java API
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.