This is an automated email from the ASF dual-hosted git repository.
udo pushed a commit to branch support/1.13
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/support/1.13 by this push:
new b3fd74a GEODE-8174: Fix ConcurrentModificationException when using
JTA transaction. (#5170)
b3fd74a is described below
commit b3fd74a17e6e8c76e5602ca700c33939dccbf10f
Author: Udo Kohlmeyer <[email protected]>
AuthorDate: Wed May 27 13:48:11 2020 -0700
GEODE-8174: Fix ConcurrentModificationException when using JTA transaction.
(#5170)
(cherry picked from commit 93ef47c8c4d8712f60c2961fce1b28457fe447cc)
Co-authored-by: Udo Kohlmeyer <[email protected]>
---
.../internal/ra/spi/JCAManagedConnection.java | 33 +++++++++++++---------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git
a/geode-core/src/jca/java/org/apache/geode/internal/ra/spi/JCAManagedConnection.java
b/geode-core/src/jca/java/org/apache/geode/internal/ra/spi/JCAManagedConnection.java
index c654e64..575b2a2 100644
---
a/geode-core/src/jca/java/org/apache/geode/internal/ra/spi/JCAManagedConnection.java
+++
b/geode-core/src/jca/java/org/apache/geode/internal/ra/spi/JCAManagedConnection.java
@@ -12,15 +12,14 @@
* or implied. See the License for the specific language governing permissions
and limitations under
* the License.
*/
+
package org.apache.geode.internal.ra.spi;
import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
@@ -35,13 +34,14 @@ import javax.transaction.xa.XAResource;
import org.apache.geode.LogWriter;
import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.internal.CopyOnWriteHashSet;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.TXManagerImpl;
import org.apache.geode.internal.ra.GFConnectionImpl;
public class JCAManagedConnection implements ManagedConnection {
- private final List<ConnectionEventListener> listeners;
+ private final List<ConnectionEventListener> listeners = new
CopyOnWriteArrayList<>();;
private volatile TXManagerImpl transactionManager;
@@ -53,15 +53,12 @@ public class JCAManagedConnection implements
ManagedConnection {
private final JCAManagedConnectionFactory connectionFactory;
- private final Set<GFConnectionImpl> connections;
+ private final Set<GFConnectionImpl> connections = new
CopyOnWriteHashSet<>();;
- private volatile JCALocalTransaction localTransaction;
+ private volatile JCALocalTransaction localTransaction = new
JCALocalTransaction();;
JCAManagedConnection(JCAManagedConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
- this.listeners = Collections.synchronizedList(new ArrayList<>());
- this.localTransaction = new JCALocalTransaction();
- this.connections = Collections.synchronizedSet(new HashSet<>());
}
@Override
@@ -90,7 +87,7 @@ public class JCAManagedConnection implements
ManagedConnection {
}
}
if (this.localTransaction == null ||
this.localTransaction.transactionInProgress()) {
- if (this.initialized && !this.cache.isClosed()) {
+ if (this.initialized && !isCacheClosed()) {
this.localTransaction = new JCALocalTransaction(this.cache,
this.transactionManager);
} else {
this.localTransaction = new JCALocalTransaction();
@@ -98,6 +95,13 @@ public class JCAManagedConnection implements
ManagedConnection {
}
}
+ private boolean isCacheClosed() {
+ if (this.cache != null) {
+ return this.cache.isClosed();
+ }
+ return true;
+ }
+
@Override
public void destroy() throws ResourceException {
synchronized (this.connections) {
@@ -116,7 +120,7 @@ public class JCAManagedConnection implements
ManagedConnection {
@Override
public Object getConnection(Subject arg0, ConnectionRequestInfo arg1) throws
ResourceException {
- if (!this.initialized || this.cache.isClosed()) {
+ if (!this.initialized || isCacheClosed()) {
init();
}
LogWriter logger = this.cache.getLogger();
@@ -131,6 +135,9 @@ public class JCAManagedConnection implements
ManagedConnection {
private void init() {
this.cache = (InternalCache) CacheFactory.getAnyInstance();
+ if (this.cache == null) {
+ throw new RuntimeException("Cache could not be found in
JCAManagedConnection");
+ }
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection:init. Inside init");
@@ -151,7 +158,7 @@ public class JCAManagedConnection implements
ManagedConnection {
@Override
public ManagedConnectionMetaData getMetaData() throws ResourceException {
- if (this.initialized && !this.cache.isClosed()) {
+ if (this.initialized && !isCacheClosed()) {
LogWriter logger = this.cache.getLogger();
if (logger.fineEnabled()) {
logger.fine("JCAManagedConnection:getMetaData");
@@ -215,7 +222,7 @@ public class JCAManagedConnection implements
ManagedConnection {
if (this.connections.isEmpty()) {
// safe to dissociate this managed connection so that it can go to pool
- if (this.initialized && !this.cache.isClosed()) {
+ if (this.initialized && !isCacheClosed()) {
this.localTransaction = new JCALocalTransaction(this.cache,
this.transactionManager);
} else {
this.localTransaction = new JCALocalTransaction();