Author |
Message
|
abhay09 |
Posted: Wed Dec 20, 2017 6:10 am Post subject: How to give thread time out in MQ Java API |
|
|
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 |
|
 |
fjb_saper |
Posted: Wed Dec 20, 2017 8:41 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 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 |
|
 |
abhay09 |
Posted: Wed Dec 20, 2017 8:58 am Post subject: |
|
|
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 |
|
 |
tczielke |
Posted: Wed Dec 20, 2017 12:06 pm Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Dec 21, 2017 5:54 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
And here I thought you'd really need this in combination of TCP Keep_Alive...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
tczielke |
Posted: Thu Dec 21, 2017 3:23 pm Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 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. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
abhay09 |
Posted: Tue Dec 26, 2017 10:52 pm Post subject: |
|
|
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 |
|
 |
abhay09 |
Posted: Tue Dec 26, 2017 11:00 pm Post subject: How to handle MQ API under network delay of 5 seconds |
|
|
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 |
|
 |
|