diff --git a/org/postgresql/xa/PGXAConnection.java b/org/postgresql/xa/PGXAConnection.java
index c70d033..b320985 100644
--- a/org/postgresql/xa/PGXAConnection.java
+++ b/org/postgresql/xa/PGXAConnection.java
@@ -95,7 +95,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
 
     /**** XAConnection interface ****/
 
-    public Connection getConnection() throws SQLException
+    public synchronized Connection getConnection() throws SQLException
     {
         if (logger.logDebug())
             debug("PGXAConnection.getConnection called");
@@ -137,23 +137,34 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
         public Object invoke(Object proxy, Method method, Object[] args)
         throws Throwable
         {
-	    if (state != STATE_IDLE)
+	    String methodName = method.getName();
+	    if (methodName.equals("commit") ||
+		methodName.equals("rollback") ||
+		methodName.equals("setSavePoint") ||
+		(methodName.equals("setAutoCommit") && ((Boolean) args[0]).booleanValue()))
             {
-                String methodName = method.getName();
-                if (methodName.equals("commit") ||
-                    methodName.equals("rollback") ||
-                    methodName.equals("setSavePoint") ||
-                    (methodName.equals("setAutoCommit") && ((Boolean) args[0]).booleanValue()))
-                {
-		    throw new PSQLException(GT.tr("Transaction control methods setAutoCommit(true), commit, rollback and setSavePoint not allowed while an XA transaction is active."),
-					    PSQLState.OBJECT_NOT_IN_STATE);
-                }
-            }
-            try {
-                return method.invoke(con, args);
-            } catch (InvocationTargetException ex) {
-                throw ex.getTargetException();
+		synchronized(PGXAConnection.this)
+		{
+		    if (state != STATE_IDLE)
+		    {
+			throw new PSQLException(GT.tr("Transaction control methods setAutoCommit(true), commit, rollback and setSavePoint not allowed while an XA transaction is active."),
+						PSQLState.OBJECT_NOT_IN_STATE);
+		    }
+		    try {
+			return method.invoke(con, args);
+		    } catch (InvocationTargetException ex) {
+			throw ex.getTargetException();
+		    }
+		}
             }
+	    else
+	    {
+		try {
+		    return method.invoke(con, args);
+		} catch (InvocationTargetException ex) {
+		    throw ex.getTargetException();
+		}
+	    }
         }
     }
 
@@ -177,7 +188,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
      * Postconditions:
      * 1. Connection is associated with the transaction
      */
-    public void start(Xid xid, int flags) throws XAException {
+    public synchronized void start(Xid xid, int flags) throws XAException {
         if (logger.logDebug())
             debug("starting transaction xid = " + xid);
 
@@ -235,7 +246,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
      * Postconditions:
      * 1. connection is disassociated from the transaction.
      */
-    public void end(Xid xid, int flags) throws XAException {
+    public synchronized void end(Xid xid, int flags) throws XAException {
         if (logger.logDebug())
             debug("ending transaction xid = " + xid);
 
@@ -272,7 +283,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
      * Postconditions:
      * 1. Transaction is prepared
      */
-    public int prepare(Xid xid) throws XAException {
+    public synchronized int prepare(Xid xid) throws XAException {
         if (logger.logDebug())
             debug("preparing transaction xid = " + xid);
 
@@ -322,7 +333,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
      * Postconditions:
      * 1. list of prepared xids is returned
      */
-    public Xid[] recover(int flag) throws XAException {
+    public synchronized Xid[] recover(int flag) throws XAException {
         // Check preconditions
         if (flag != TMSTARTRSCAN && flag != TMENDRSCAN && flag != TMNOFLAGS && flag != (TMSTARTRSCAN | TMENDRSCAN))
             throw new PGXAException(GT.tr("Invalid flag"), XAException.XAER_INVAL);
@@ -380,7 +391,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
      * Postconditions:
      * 1. Transaction is rolled back and disassociated from connection
      */
-    public void rollback(Xid xid) throws XAException {
+    public synchronized void rollback(Xid xid) throws XAException {
         if (logger.logDebug())
             debug("rolling back xid = " + xid);
 
@@ -417,7 +428,7 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
         }
     }
 
-    public void commit(Xid xid, boolean onePhase) throws XAException {
+    public synchronized void commit(Xid xid, boolean onePhase) throws XAException {
         if (logger.logDebug())
             debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)"));
 
