openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpala...@apache.org
Subject svn commit: r1087361 - in /openjpa/branches/1.1.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-persistence-jdbc/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/
Date Thu, 31 Mar 2011 16:22:11 GMT
Author: rpalache
Date: Thu Mar 31 16:22:11 2011
New Revision: 1087361

URL: http://svn.apache.org/viewvc?rev=1087361&view=rev
Log:
OPENJPA-1970 CPU spinning forever at TreeMap.get in Schema.java

Added:
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaMultithreaded.java
Modified:
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/pom.xml

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java?rev=1087361&r1=1087360&r2=1087361&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java
Thu Mar 31 16:22:11 2011
@@ -19,6 +19,7 @@
 package org.apache.openjpa.jdbc.schema;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -127,7 +128,7 @@ public class Schema
         } else
             tab = new Table(name, this);
         if (_tableMap == null)
-            _tableMap = new TreeMap();
+            _tableMap = Collections.synchronizedMap(new TreeMap());
         _tableMap.put(name.toUpperCase(), tab);
         _tables = null;
         return tab;
@@ -203,7 +204,7 @@ public class Schema
         } else
             seq = new Sequence(name, this);
         if (_seqMap == null)
-            _seqMap = new TreeMap();
+            _seqMap = Collections.synchronizedMap(new TreeMap());
         _seqMap.put(name.toUpperCase(), seq);
         _seqs = null;
         return seq;

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/pom.xml?rev=1087361&r1=1087360&r2=1087361&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/pom.xml (original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/pom.xml Thu Mar 31 16:22:11 2011
@@ -439,6 +439,7 @@
                         <exclude>org/apache/openjpa/persistence/jdbc/schema/TestSchema.java</exclude>
                         <exclude>org/apache/openjpa/persistence/jdbc/schema/TestSchemaClone.java</exclude>
                         <exclude>org/apache/openjpa/persistence/jdbc/schema/TestSchemaGenerator.java</exclude>
+                        <exclude>org/apache/openjpa/persistence/jdbc/schema/TestSchemaMultithreaded.java</exclude>
                       
                         <exclude>org/apache/openjpa/persistence/jdbc/schema/TestSequenceGeneratorEnsureCapacityCall.java</exclude>
                         <exclude>org/apache/openjpa/persistence/jdbc/schema/TestXMLSchemaParser.java</exclude>
                         <exclude>org/apache/openjpa/persistence/jdbc/schema/TestXMLSchemaSerializer.java</exclude>

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaMultithreaded.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaMultithreaded.java?rev=1087361&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaMultithreaded.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaMultithreaded.java
Thu Mar 31 16:22:11 2011
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.jdbc.schema;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ForeignKey;
+import org.apache.openjpa.jdbc.schema.Index;
+import org.apache.openjpa.jdbc.schema.PrimaryKey;
+import org.apache.openjpa.jdbc.schema.Schema;
+import org.apache.openjpa.jdbc.schema.SchemaGroup;
+import org.apache.openjpa.jdbc.schema.Table;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest;
+
+public class TestSchemaMultithreaded extends BaseJDBCTest {
+
+    private int THREADS = 10;
+    private int LOOPCOUNT = 1000000;
+    private int THREAD = 0;
+
+    public TestSchemaMultithreaded() {
+    }
+
+    public TestSchemaMultithreaded(String test) {
+        super(test);
+    }
+
+    public void testSchemaSequence() throws InterruptedException {
+        // final Schema _schema = new SchemaGroup().addSchema("schema");
+        final Schema _schema = new Schema();
+        final SchemaGroup _schemagroup = new SchemaGroup();
+
+        Thread[] threads = new Thread[THREADS];
+
+        for (int i = 0; i < THREADS; i++) {
+            if (i % 2 == 0) {
+                THREAD = i;
+                threads[i] = new Thread(new Runnable() {
+                    public void run() {
+                        for (int i = 0; i < LOOPCOUNT; i++) {
+                            _schema.addSequence("Table:" + i + " " + THREAD);
+                        }
+                    }
+                });
+            } else {
+                THREAD = i;
+                threads[i] = new Thread(new Runnable() {
+                    public void run() {
+                        for (int i = 0; i < LOOPCOUNT; i++) {
+                            _schema.getSequence("Table:" + i + " "
+                                + (THREAD - 1));
+                        }
+                    }
+                });
+            }
+        }
+
+        for (int threadCount = 0; threadCount < THREADS; threadCount++) {
+            threads[threadCount].start();
+        }
+
+        for (int threadCount = 0; threadCount < THREADS; threadCount++) {
+            threads[threadCount].join();
+        }
+    }
+}



Mime
View raw message