You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2017/01/04 02:57:59 UTC

cxf git commit: [CXF-7205]In JmsPullPoint create session for producer and consumer separately and synchronized the session but not the whole method to avoid deadlock

Repository: cxf
Updated Branches:
  refs/heads/master e66950983 -> 0d797ec55


[CXF-7205]In JmsPullPoint create session for producer and consumer separately and synchronized the session but not the whole method to avoid deadlock


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0d797ec5
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0d797ec5
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0d797ec5

Branch: refs/heads/master
Commit: 0d797ec552bb39210f9d21fdec09b8267d9a348c
Parents: e669509
Author: Freeman Fang <fr...@gmail.com>
Authored: Wed Jan 4 10:57:43 2017 +0800
Committer: Freeman Fang <fr...@gmail.com>
Committed: Wed Jan 4 10:57:43 2017 +0800

----------------------------------------------------------------------
 .../org/apache/cxf/wsn/jms/JmsPullPoint.java    | 44 ++++++++++++++------
 1 file changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0d797ec5/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
----------------------------------------------------------------------
diff --git a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
index b56fe92..5dcffbe 100644
--- a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
+++ b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsPullPoint.java
@@ -55,7 +55,9 @@ public class JmsPullPoint extends AbstractPullPoint {
 
     private Connection connection;
 
-    private Session session;
+    private Session producerSession;
+    
+    private Session consumerSession;
 
     private Queue queue;
 
@@ -73,22 +75,33 @@ public class JmsPullPoint extends AbstractPullPoint {
     }
 
     protected synchronized void initSession() throws JMSException {
-        if (session == null) {
-            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-            queue = session.createQueue(getName());
-            producer = session.createProducer(queue);
-            consumer = session.createConsumer(queue);
+        if (producerSession == null || consumerSession == null) {
+            producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            queue = producerSession.createQueue(getName());
+            producer = producerSession.createProducer(queue);
+            consumer = consumerSession.createConsumer(queue);
         }
     }
     
     protected synchronized void closeSession() {
-        if (session != null) {
+        if (producerSession != null) {
+            try {
+                producerSession.close();
+            } catch (JMSException inner) {
+                LOGGER.log(Level.FINE, "Error closing ProducerSession", inner);
+            } finally {
+                producerSession = null;
+            }
+        }
+        
+        if (consumerSession != null) {
             try {
-                session.close();
+                consumerSession.close();
             } catch (JMSException inner) {
-                LOGGER.log(Level.FINE, "Error closing session", inner);
+                LOGGER.log(Level.FINE, "Error closing ConsumerSession", inner);
             } finally {
-                session = null;
+                consumerSession = null;
             }
         }
     }
@@ -101,8 +114,10 @@ public class JmsPullPoint extends AbstractPullPoint {
             notify.getNotificationMessage().add(messageHolder);
             StringWriter writer = new StringWriter();
             jaxbContext.createMarshaller().marshal(notify, writer);
-            Message message = session.createTextMessage(writer.toString());
-            producer.send(message);
+            synchronized (producerSession) {
+                Message message = producerSession.createTextMessage(writer.toString());
+                producer.send(message);
+            }
         } catch (JMSException e) {
             LOGGER.log(Level.WARNING, "Error storing message", e);
             closeSession();
@@ -122,7 +137,10 @@ public class JmsPullPoint extends AbstractPullPoint {
             initSession();
             List<NotificationMessageHolderType> messages = new ArrayList<NotificationMessageHolderType>();
             for (int i = 0; i < max; i++) {
-                Message msg = consumer.receiveNoWait();
+                Message msg = null;
+                synchronized (consumerSession) {
+                    msg = consumer.receiveNoWait();
+                }
                 if (msg == null) {
                     break;
                 }