Repository: cxf Updated Branches: refs/heads/3.1.x-fixes dbc867f98 -> 7e57ca653
[CXF-7145]synchronized store and getMessages of JmsPullPoint would cause deadlock Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/574090d1 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/574090d1 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/574090d1 Branch: refs/heads/3.1.x-fixes Commit: 574090d1180ae3718ffe1ab9dbbb6f49ad67b5a2 Parents: 979fe8e Author: Freeman Fang <[email protected]> Authored: Tue Nov 22 16:10:36 2016 +0800 Committer: Freeman Fang <[email protected]> Committed: Tue Nov 22 16:10:36 2016 +0800 ---------------------------------------------------------------------- .../org/apache/cxf/wsn/jms/JmsPullPoint.java | 39 +++++++++----------- 1 file changed, 18 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/574090d1/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 92d50ae..b56fe92 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 @@ -72,7 +72,7 @@ public class JmsPullPoint extends AbstractPullPoint { } } - protected void initSession() throws JMSException { + protected synchronized void initSession() throws JMSException { if (session == null) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue(getName()); @@ -80,9 +80,21 @@ public class JmsPullPoint extends AbstractPullPoint { consumer = session.createConsumer(queue); } } + + protected synchronized void closeSession() { + if (session != null) { + try { + session.close(); + } catch (JMSException inner) { + LOGGER.log(Level.FINE, "Error closing session", inner); + } finally { + session = null; + } + } + } @Override - protected synchronized void store(NotificationMessageHolderType messageHolder) { + protected void store(NotificationMessageHolderType messageHolder) { try { initSession(); Notify notify = new Notify(); @@ -93,22 +105,15 @@ public class JmsPullPoint extends AbstractPullPoint { producer.send(message); } catch (JMSException e) { LOGGER.log(Level.WARNING, "Error storing message", e); - if (session != null) { - try { - session.close(); - } catch (JMSException inner) { - LOGGER.log(Level.FINE, "Error closing session", inner); - } finally { - session = null; - } - } + closeSession(); + } catch (JAXBException e) { LOGGER.log(Level.WARNING, "Error storing message", e); } } @Override - protected synchronized List<NotificationMessageHolderType> getMessages(int max) + protected List<NotificationMessageHolderType> getMessages(int max) throws ResourceUnknownFault, UnableToGetMessagesFault { try { if (max == 0) { @@ -135,15 +140,7 @@ public class JmsPullPoint extends AbstractPullPoint { return messages; } catch (JMSException e) { LOGGER.log(Level.INFO, "Error retrieving messages", e); - if (session != null) { - try { - session.close(); - } catch (JMSException inner) { - LOGGER.log(Level.FINE, "Error closing session", inner); - } finally { - session = null; - } - } + closeSession(); UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType(); throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e); } catch (JAXBException e) {
