From 9dff400ff6521a4bad2ef9d2281f9e8c864c3842 Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 28 Sep 2011 14:20:00 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BB=BF=E7=85=A7JBOSS=E5=AE=9E=E7=8E=B0Prepar?= =?UTF-8?q?edStatementCache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@912 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- 1 | 125 +++++++++ 2 | 167 ++++++++++++ 3 | 167 ++++++++++++ 4 | 167 ++++++++++++ .../alibaba/druid/pool/ConnectionHolder.java | 4 +- .../druid/pool/PoolableCallableStatement.java | 3 +- .../druid/pool/PoolableConnection.java | 243 +++++++----------- .../druid/pool/PoolablePreparedStatement.java | 82 +++++- .../alibaba/druid/pool/PoolableStatement.java | 12 +- .../druid/pool/PreparedStatementPool.java | 37 +-- .../druid/sql/parser/SQLExprParser.java | 8 +- .../com/alibaba/druid/stat/JdbcSqlStat.java | 6 +- .../alibaba/druid/bvt/pool/TestClose_1.java | 5 +- .../alibaba/druid/bvt/pool/TestClose_2.java | 5 +- .../pool/basic/PreparedStatementKeyTest.java | 3 +- .../bvt/proxy/filter/StatFilterTest.java | 3 +- 16 files changed, 832 insertions(+), 205 deletions(-) create mode 100644 1 create mode 100644 2 create mode 100644 3 create mode 100644 4 diff --git a/1 b/1 new file mode 100644 index 0000000000..c9013546c8 --- /dev/null +++ b/1 @@ -0,0 +1,125 @@ +2011-09-28 15:52:42 +Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.1-b02-383 mixed mode): + +"Attach Listener" daemon prio=9 tid=7f9c4581f000 nid=0x11051f000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + +"XXX" prio=5 tid=7f9c42015000 nid=0x1113d4000 waiting on condition [1113d3000] + java.lang.Thread.State: WAITING (parking) + at sun.misc.Unsafe.park(Native Method) + - parking to wait for <7f316ec30> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178) + at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186) + at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262) + at com.alibaba.json.test.TestMemory$1.run(TestMemory.java:21) + +"ReaderThread" prio=5 tid=7f9c4609b000 nid=0x1112d1000 runnable [1112d0000] + java.lang.Thread.State: RUNNABLE + at java.net.SocketInputStream.socketRead0(Native Method) + at java.net.SocketInputStream.read(SocketInputStream.java:129) + at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) + at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) + at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.InputStreamReader.read(InputStreamReader.java:167) + at java.io.BufferedReader.fill(BufferedReader.java:136) + at java.io.BufferedReader.readLine(BufferedReader.java:299) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.BufferedReader.readLine(BufferedReader.java:362) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner$ReaderThread.run(RemoteTestRunner.java:140) + +"Low Memory Detector" daemon prio=5 tid=7f9c46002800 nid=0x110d40000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + +"C2 CompilerThread1" daemon prio=9 tid=7f9c46000000 nid=0x110c3d000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + +"C2 CompilerThread0" daemon prio=9 tid=7f9c46001000 nid=0x110b3a000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + +"JDWP Command Reader" daemon prio=5 tid=7f9c45810800 nid=0x110a37000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + +"JDWP Event Helper Thread" daemon prio=5 tid=7f9c45810000 nid=0x110934000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + +"JDWP Transport Listener: dt_socket" daemon prio=5 tid=7f9c4580f000 nid=0x110831000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + +"Signal Dispatcher" daemon prio=9 tid=7f9c42009800 nid=0x110728000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + +"Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7f9c42008800 nid=0x110625000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + +"Finalizer" daemon prio=8 tid=7f9c4293a800 nid=0x110361000 in Object.wait() [110360000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) + - locked <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) + at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159) + +"Reference Handler" daemon prio=10 tid=7f9c4293a000 nid=0x11025e000 in Object.wait() [11025d000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e011d8> (a java.lang.ref.Reference$Lock) + at java.lang.Object.wait(Object.java:485) + at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) + - locked <7f2e011d8> (a java.lang.ref.Reference$Lock) + +"main" prio=5 tid=7f9c42802000 nid=0x108486000 at breakpoint[108484000] + java.lang.Thread.State: RUNNABLE + at com.alibaba.json.test.TestMemory.test_0(TestMemory.java:28) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at junit.framework.TestCase.runTest(TestCase.java:168) + at junit.framework.TestCase.runBare(TestCase.java:134) + at junit.framework.TestResult$1.protect(TestResult.java:110) + at junit.framework.TestResult.runProtected(TestResult.java:128) + at junit.framework.TestResult.run(TestResult.java:113) + at junit.framework.TestCase.run(TestCase.java:124) + at junit.framework.TestSuite.runTest(TestSuite.java:232) + at junit.framework.TestSuite.run(TestSuite.java:227) + at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79) + at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) + at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) + +"VM Thread" prio=9 tid=7f9c42935800 nid=0x11015b000 runnable + +"Gang worker#0 (Parallel GC Threads)" prio=9 tid=7f9c42803800 nid=0x10b7fe000 runnable + +"Gang worker#1 (Parallel GC Threads)" prio=9 tid=7f9c42804000 nid=0x10b901000 runnable + +"Gang worker#2 (Parallel GC Threads)" prio=9 tid=7f9c42804800 nid=0x10ba04000 runnable + +"Gang worker#3 (Parallel GC Threads)" prio=9 tid=7f9c42805000 nid=0x10bb07000 runnable + +"Gang worker#4 (Parallel GC Threads)" prio=9 tid=7f9c42806000 nid=0x10bc0a000 runnable + +"Gang worker#5 (Parallel GC Threads)" prio=9 tid=7f9c42806800 nid=0x10bd0d000 runnable + +"Gang worker#6 (Parallel GC Threads)" prio=9 tid=7f9c42807000 nid=0x10be10000 runnable + +"Gang worker#7 (Parallel GC Threads)" prio=9 tid=7f9c42807800 nid=0x10bf13000 runnable + +"Concurrent Mark-Sweep GC Thread" prio=9 tid=7f9c428e5000 nid=0x10fe00000 runnable +"Gang worker#0 (Parallel CMS Threads)" prio=9 tid=7f9c428e4000 nid=0x10f3fa000 runnable + +"Gang worker#1 (Parallel CMS Threads)" prio=9 tid=7f9c428e4800 nid=0x10f4fd000 runnable + +"VM Periodic Task Thread" prio=10 tid=7f9c46014000 nid=0x110e43000 waiting on condition + +"Exception Catcher Thread" prio=10 tid=7f9c42802800 nid=0x108625000 runnable +JNI global references: 2185 + diff --git a/2 b/2 new file mode 100644 index 0000000000..4f765e9c6f --- /dev/null +++ b/2 @@ -0,0 +1,167 @@ +2011-09-28 15:53:56 +Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.1-b02-383 mixed mode): + +"Attach Listener" daemon prio=9 tid=7f92e525e000 nid=0x115116000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"XXX" prio=5 tid=7f92ea800000 nid=0x115fdc000 waiting on condition [115fdb000] + java.lang.Thread.State: WAITING (parking) + at sun.misc.Unsafe.park(Native Method) + - parking to wait for <7f316ec30> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178) + at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186) + at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262) + at com.alibaba.json.test.TestMemory$1.run(TestMemory.java:21) + + Locked ownable synchronizers: + - <7f316ec00> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + +"ReaderThread" prio=5 tid=7f92e4086000 nid=0x115ed9000 runnable [115ed8000] + java.lang.Thread.State: RUNNABLE + at java.net.SocketInputStream.socketRead0(Native Method) + at java.net.SocketInputStream.read(SocketInputStream.java:129) + at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) + at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) + at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.InputStreamReader.read(InputStreamReader.java:167) + at java.io.BufferedReader.fill(BufferedReader.java:136) + at java.io.BufferedReader.readLine(BufferedReader.java:299) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.BufferedReader.readLine(BufferedReader.java:362) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner$ReaderThread.run(RemoteTestRunner.java:140) + + Locked ownable synchronizers: + - None + +"Low Memory Detector" daemon prio=5 tid=7f92e5140800 nid=0x115937000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"C2 CompilerThread1" daemon prio=9 tid=7f92e513f000 nid=0x115834000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"C2 CompilerThread0" daemon prio=9 tid=7f92e5140000 nid=0x115731000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Command Reader" daemon prio=5 tid=7f92e400f800 nid=0x11562e000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Event Helper Thread" daemon prio=5 tid=7f92e880f800 nid=0x11552b000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Transport Listener: dt_socket" daemon prio=5 tid=7f92e8810800 nid=0x115428000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Signal Dispatcher" daemon prio=9 tid=7f92e880d800 nid=0x11531f000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7f92e880c800 nid=0x11521c000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Finalizer" daemon prio=8 tid=7f92e5135000 nid=0x114f58000 in Object.wait() [114f57000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) + - locked <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) + at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159) + + Locked ownable synchronizers: + - None + +"Reference Handler" daemon prio=10 tid=7f92e5134000 nid=0x114e55000 in Object.wait() [114e54000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e011d8> (a java.lang.ref.Reference$Lock) + at java.lang.Object.wait(Object.java:485) + at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) + - locked <7f2e011d8> (a java.lang.ref.Reference$Lock) + + Locked ownable synchronizers: + - None + +"main" prio=5 tid=7f92e5001800 nid=0x10d07d000 at breakpoint[10d07b000] + java.lang.Thread.State: RUNNABLE + at com.alibaba.json.test.TestMemory.test_0(TestMemory.java:28) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at junit.framework.TestCase.runTest(TestCase.java:168) + at junit.framework.TestCase.runBare(TestCase.java:134) + at junit.framework.TestResult$1.protect(TestResult.java:110) + at junit.framework.TestResult.runProtected(TestResult.java:128) + at junit.framework.TestResult.run(TestResult.java:113) + at junit.framework.TestCase.run(TestCase.java:124) + at junit.framework.TestSuite.runTest(TestSuite.java:232) + at junit.framework.TestSuite.run(TestSuite.java:227) + at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79) + at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) + at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) + + Locked ownable synchronizers: + - <7f316ec30> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + +"VM Thread" prio=9 tid=7f92e512f800 nid=0x114d52000 runnable + +"Gang worker#0 (Parallel GC Threads)" prio=9 tid=7f92e8000000 nid=0x1103f5000 runnable + +"Gang worker#1 (Parallel GC Threads)" prio=9 tid=7f92e8800000 nid=0x1104f8000 runnable + +"Gang worker#2 (Parallel GC Threads)" prio=9 tid=7f92e8801000 nid=0x1105fb000 runnable + +"Gang worker#3 (Parallel GC Threads)" prio=9 tid=7f92e8801800 nid=0x1106fe000 runnable + +"Gang worker#4 (Parallel GC Threads)" prio=9 tid=7f92e8802000 nid=0x110801000 runnable + +"Gang worker#5 (Parallel GC Threads)" prio=9 tid=7f92e8802800 nid=0x110904000 runnable + +"Gang worker#6 (Parallel GC Threads)" prio=9 tid=7f92e8803800 nid=0x110a07000 runnable + +"Gang worker#7 (Parallel GC Threads)" prio=9 tid=7f92e8804000 nid=0x110b0a000 runnable + +"Concurrent Mark-Sweep GC Thread" prio=9 tid=7f92e50df000 nid=0x1149f7000 runnable +"Gang worker#0 (Parallel CMS Threads)" prio=9 tid=7f92e50de000 nid=0x113ff1000 runnable + +"Gang worker#1 (Parallel CMS Threads)" prio=9 tid=7f92e50de800 nid=0x1140f4000 runnable + +"VM Periodic Task Thread" prio=10 tid=7f92e5152000 nid=0x115a3a000 waiting on condition + +"Exception Catcher Thread" prio=10 tid=7f92e5002800 nid=0x10d21c000 runnable +JNI global references: 2184 + diff --git a/3 b/3 new file mode 100644 index 0000000000..df7251893c --- /dev/null +++ b/3 @@ -0,0 +1,167 @@ +2011-09-28 15:57:06 +Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.1-b02-383 mixed mode): + +"Attach Listener" daemon prio=9 tid=7fbdee0f8800 nid=0x10b772000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"XXX" prio=5 tid=7fbdee200000 nid=0x10c604000 waiting on condition [10c603000] + java.lang.Thread.State: WAITING (parking) + at sun.misc.Unsafe.park(Native Method) + - parking to wait for <7f316ecd0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178) + at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186) + at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262) + at com.alibaba.json.test.TestMemory$1.run(TestMemory.java:22) + + Locked ownable synchronizers: + - <7f316ed00> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + +"ReaderThread" prio=5 tid=7fbdeb06d800 nid=0x10c501000 runnable [10c500000] + java.lang.Thread.State: RUNNABLE + at java.net.SocketInputStream.socketRead0(Native Method) + at java.net.SocketInputStream.read(SocketInputStream.java:129) + at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) + at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) + at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.InputStreamReader.read(InputStreamReader.java:167) + at java.io.BufferedReader.fill(BufferedReader.java:136) + at java.io.BufferedReader.readLine(BufferedReader.java:299) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.BufferedReader.readLine(BufferedReader.java:362) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner$ReaderThread.run(RemoteTestRunner.java:140) + + Locked ownable synchronizers: + - None + +"Low Memory Detector" daemon prio=5 tid=7fbdf0000000 nid=0x10bf93000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"C2 CompilerThread1" daemon prio=9 tid=7fbdeb000800 nid=0x10be90000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"C2 CompilerThread0" daemon prio=9 tid=7fbdeb001800 nid=0x10bd8d000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Command Reader" daemon prio=5 tid=7fbded000800 nid=0x10bc8a000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Event Helper Thread" daemon prio=5 tid=7fbdeb811800 nid=0x10bb87000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Transport Listener: dt_socket" daemon prio=5 tid=7fbdeb811000 nid=0x10ba84000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Signal Dispatcher" daemon prio=9 tid=7fbdee143000 nid=0x10b97b000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7fbdee142000 nid=0x10b878000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Finalizer" daemon prio=8 tid=7fbdee139800 nid=0x10b5b6000 in Object.wait() [10b5b5000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) + - locked <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) + at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159) + + Locked ownable synchronizers: + - None + +"Reference Handler" daemon prio=10 tid=7fbdee138800 nid=0x10b4b3000 in Object.wait() [10b4b2000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e011d8> (a java.lang.ref.Reference$Lock) + at java.lang.Object.wait(Object.java:485) + at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) + - locked <7f2e011d8> (a java.lang.ref.Reference$Lock) + + Locked ownable synchronizers: + - None + +"main" prio=5 tid=7fbdee000800 nid=0x1036df000 at breakpoint[1036dd000] + java.lang.Thread.State: RUNNABLE + at com.alibaba.json.test.TestMemory.test_0(TestMemory.java:39) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at junit.framework.TestCase.runTest(TestCase.java:168) + at junit.framework.TestCase.runBare(TestCase.java:134) + at junit.framework.TestResult$1.protect(TestResult.java:110) + at junit.framework.TestResult.runProtected(TestResult.java:128) + at junit.framework.TestResult.run(TestResult.java:113) + at junit.framework.TestCase.run(TestCase.java:124) + at junit.framework.TestSuite.runTest(TestSuite.java:232) + at junit.framework.TestSuite.run(TestSuite.java:227) + at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79) + at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) + at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) + + Locked ownable synchronizers: + - <7f316ecd0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + +"VM Thread" prio=9 tid=7fbdee134000 nid=0x10b3b0000 runnable + +"Gang worker#0 (Parallel GC Threads)" prio=9 tid=7fbdee002000 nid=0x106a55000 runnable + +"Gang worker#1 (Parallel GC Threads)" prio=9 tid=7fbdee002800 nid=0x106b58000 runnable + +"Gang worker#2 (Parallel GC Threads)" prio=9 tid=7fbdee003000 nid=0x106c5b000 runnable + +"Gang worker#3 (Parallel GC Threads)" prio=9 tid=7fbdee004000 nid=0x106d5e000 runnable + +"Gang worker#4 (Parallel GC Threads)" prio=9 tid=7fbdee004800 nid=0x106e61000 runnable + +"Gang worker#5 (Parallel GC Threads)" prio=9 tid=7fbdee005000 nid=0x106f64000 runnable + +"Gang worker#6 (Parallel GC Threads)" prio=9 tid=7fbdee005800 nid=0x107067000 runnable + +"Gang worker#7 (Parallel GC Threads)" prio=9 tid=7fbdee006800 nid=0x10716a000 runnable + +"Concurrent Mark-Sweep GC Thread" prio=9 tid=7fbdee0e3800 nid=0x10b056000 runnable +"Gang worker#0 (Parallel CMS Threads)" prio=9 tid=7fbdee0e2800 nid=0x10a650000 runnable + +"Gang worker#1 (Parallel CMS Threads)" prio=9 tid=7fbdee0e3000 nid=0x10a753000 runnable + +"VM Periodic Task Thread" prio=10 tid=7fbdee145000 nid=0x10c096000 waiting on condition + +"Exception Catcher Thread" prio=10 tid=7fbdee001800 nid=0x10387e000 runnable +JNI global references: 2257 + diff --git a/4 b/4 new file mode 100644 index 0000000000..9711cd0cd8 --- /dev/null +++ b/4 @@ -0,0 +1,167 @@ +2011-09-28 15:58:33 +Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.1-b02-383 mixed mode): + +"Attach Listener" daemon prio=9 tid=7fd50981a800 nid=0x10d008000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"XXX" prio=5 tid=7fd50db05800 nid=0x10de9c000 waiting on condition [10de9b000] + java.lang.Thread.State: WAITING (parking) + at sun.misc.Unsafe.park(Native Method) + - parking to wait for <7f316ecd0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842) + at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178) + at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186) + at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262) + at com.alibaba.json.test.TestMemory$1.run(TestMemory.java:22) + + Locked ownable synchronizers: + - <7f316ed00> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + +"ReaderThread" prio=5 tid=7fd50c083000 nid=0x10dd99000 runnable [10dd98000] + java.lang.Thread.State: RUNNABLE + at java.net.SocketInputStream.socketRead0(Native Method) + at java.net.SocketInputStream.read(SocketInputStream.java:129) + at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) + at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) + at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.InputStreamReader.read(InputStreamReader.java:167) + at java.io.BufferedReader.fill(BufferedReader.java:136) + at java.io.BufferedReader.readLine(BufferedReader.java:299) + - locked <7f2fdb548> (a java.io.InputStreamReader) + at java.io.BufferedReader.readLine(BufferedReader.java:362) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner$ReaderThread.run(RemoteTestRunner.java:140) + + Locked ownable synchronizers: + - None + +"Low Memory Detector" daemon prio=5 tid=7fd510800000 nid=0x10d829000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"C2 CompilerThread1" daemon prio=9 tid=7fd50f800000 nid=0x10d726000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"C2 CompilerThread0" daemon prio=9 tid=7fd509810000 nid=0x10d623000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Command Reader" daemon prio=5 tid=7fd50f00d800 nid=0x10d520000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Event Helper Thread" daemon prio=5 tid=7fd50f00b800 nid=0x10d41d000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"JDWP Transport Listener: dt_socket" daemon prio=5 tid=7fd50f00c000 nid=0x10d31a000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Signal Dispatcher" daemon prio=9 tid=7fd50f009000 nid=0x10d211000 runnable [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7fd50f008000 nid=0x10d10e000 waiting on condition [00000000] + java.lang.Thread.State: RUNNABLE + + Locked ownable synchronizers: + - None + +"Finalizer" daemon prio=8 tid=7fd50d939800 nid=0x10ce4a000 in Object.wait() [10ce49000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) + - locked <7f2e01300> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) + at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159) + + Locked ownable synchronizers: + - None + +"Reference Handler" daemon prio=10 tid=7fd50d938800 nid=0x10cd47000 in Object.wait() [10cd46000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <7f2e011d8> (a java.lang.ref.Reference$Lock) + at java.lang.Object.wait(Object.java:485) + at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) + - locked <7f2e011d8> (a java.lang.ref.Reference$Lock) + + Locked ownable synchronizers: + - None + +"main" prio=5 tid=7fd50d800800 nid=0x104f70000 at breakpoint[104f6e000] + java.lang.Thread.State: RUNNABLE + at com.alibaba.json.test.TestMemory.test_0(TestMemory.java:41) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at junit.framework.TestCase.runTest(TestCase.java:168) + at junit.framework.TestCase.runBare(TestCase.java:134) + at junit.framework.TestResult$1.protect(TestResult.java:110) + at junit.framework.TestResult.runProtected(TestResult.java:128) + at junit.framework.TestResult.run(TestResult.java:113) + at junit.framework.TestCase.run(TestCase.java:124) + at junit.framework.TestSuite.runTest(TestSuite.java:232) + at junit.framework.TestSuite.run(TestSuite.java:227) + at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79) + at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) + at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) + + Locked ownable synchronizers: + - <7f316ecd0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync) + +"VM Thread" prio=9 tid=7fd50d934000 nid=0x10cc44000 runnable + +"Gang worker#0 (Parallel GC Threads)" prio=9 tid=7fd50d802000 nid=0x1082e7000 runnable + +"Gang worker#1 (Parallel GC Threads)" prio=9 tid=7fd50d802800 nid=0x1083ea000 runnable + +"Gang worker#2 (Parallel GC Threads)" prio=9 tid=7fd50d803000 nid=0x1084ed000 runnable + +"Gang worker#3 (Parallel GC Threads)" prio=9 tid=7fd50d804000 nid=0x1085f0000 runnable + +"Gang worker#4 (Parallel GC Threads)" prio=9 tid=7fd50d804800 nid=0x1086f3000 runnable + +"Gang worker#5 (Parallel GC Threads)" prio=9 tid=7fd50d805000 nid=0x1087f6000 runnable + +"Gang worker#6 (Parallel GC Threads)" prio=9 tid=7fd50d805800 nid=0x1088f9000 runnable + +"Gang worker#7 (Parallel GC Threads)" prio=9 tid=7fd50d806800 nid=0x1089fc000 runnable + +"Concurrent Mark-Sweep GC Thread" prio=9 tid=7fd50d8e3800 nid=0x10c8e9000 runnable +"Gang worker#0 (Parallel CMS Threads)" prio=9 tid=7fd50d8e2800 nid=0x10bee3000 runnable + +"Gang worker#1 (Parallel CMS Threads)" prio=9 tid=7fd50d8e3000 nid=0x10bfe6000 runnable + +"VM Periodic Task Thread" prio=10 tid=7fd50c00a000 nid=0x10d92c000 waiting on condition + +"Exception Catcher Thread" prio=10 tid=7fd50d801800 nid=0x10510f000 runnable +JNI global references: 2222 + diff --git a/src/main/java/com/alibaba/druid/pool/ConnectionHolder.java b/src/main/java/com/alibaba/druid/pool/ConnectionHolder.java index 9f8cf29033..d884b05fcb 100644 --- a/src/main/java/com/alibaba/druid/pool/ConnectionHolder.java +++ b/src/main/java/com/alibaba/druid/pool/ConnectionHolder.java @@ -67,11 +67,11 @@ public final class ConnectionHolder { this.lastActiveTimeMillis = lastActiveMillis; } - public void addTrace(Statement stmt) { + public void addTrace(PoolableStatement stmt) { statementTrace.add(stmt); } - public void removeTrace(Statement stmt) { + public void removeTrace(PoolableStatement stmt) { statementTrace.remove(stmt); } diff --git a/src/main/java/com/alibaba/druid/pool/PoolableCallableStatement.java b/src/main/java/com/alibaba/druid/pool/PoolableCallableStatement.java index 180751210e..dfaa653340 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolableCallableStatement.java +++ b/src/main/java/com/alibaba/druid/pool/PoolableCallableStatement.java @@ -36,7 +36,8 @@ public class PoolableCallableStatement extends PoolablePreparedStatement impleme private CallableStatement stmt; - public PoolableCallableStatement(PoolableConnection conn, CallableStatement stmt, PreparedStatementKey key, String sql){ + public PoolableCallableStatement(PoolableConnection conn, CallableStatement stmt, PreparedStatementKey key, + String sql) throws SQLException{ super(conn, stmt, key, sql); this.stmt = stmt; } diff --git a/src/main/java/com/alibaba/druid/pool/PoolableConnection.java b/src/main/java/com/alibaba/druid/pool/PoolableConnection.java index db43fa0663..95e3e27de0 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolableConnection.java +++ b/src/main/java/com/alibaba/druid/pool/PoolableConnection.java @@ -30,7 +30,6 @@ import java.sql.SQLXML; import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; -import java.util.List; import java.util.Map; import java.util.Properties; @@ -128,15 +127,6 @@ public class PoolableConnection implements PooledConnection, Connection { listener.connectionClosed(new ConnectionEvent(this)); } - PreparedStatementPool statementPool = holder.getStatementPool(); - if (statementPool != null) { - for (List stmtList : statementPool.getMap().values()) { - for (PoolablePreparedStatement stmt : stmtList) { - stmt.close(); - } - } - } - holder.reset(); holder.getDataSource().recycle(this); @@ -153,28 +143,23 @@ public class PoolableConnection implements PooledConnection, Connection { PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M1); - if (holder.isPoolPreparedStatements()) { - PoolablePreparedStatement poolableStatement = holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } - } - PreparedStatement stmt = null; - try { - stmt = conn.prepareStatement(sql); - } catch (SQLException ex) { - handleException(ex); + if (holder.isPoolPreparedStatements()) { + stmt = holder.getStatementPool().get(key); + } + + if (stmt == null) { + try { + stmt = conn.prepareStatement(sql); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); + PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -188,28 +173,23 @@ public class PoolableConnection implements PooledConnection, Connection { PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M2); + PreparedStatement stmt = null; + if (holder.isPoolPreparedStatements()) { - - PoolablePreparedStatement poolableStatement = holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + stmt = holder.getStatementPool().get(key); } - PreparedStatement stmt = null; - try { - stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); + PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -222,28 +202,24 @@ public class PoolableConnection implements PooledConnection, Connection { checkOpen(); PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M3); - if (holder.isPoolPreparedStatements()) { - - PoolablePreparedStatement poolableStatement = holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } - } PreparedStatement stmt = null; - try { - stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - } catch (SQLException ex) { - handleException(ex); + + if (holder.isPoolPreparedStatements()) { + stmt = holder.getStatementPool().get(key); + } + + if (stmt == null) { + try { + stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); + PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -254,28 +230,24 @@ public class PoolableConnection implements PooledConnection, Connection { public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { checkOpen(); + PreparedStatement stmt = null; + PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M4); if (holder.isPoolPreparedStatements()) { - PoolablePreparedStatement poolableStatement = holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + stmt = holder.getStatementPool().get(key); } - PreparedStatement stmt = null; - try { - stmt = conn.prepareStatement(sql, columnIndexes); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareStatement(sql, columnIndexes); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); + PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -286,28 +258,24 @@ public class PoolableConnection implements PooledConnection, Connection { public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { checkOpen(); + PreparedStatement stmt = null; + PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M5); if (holder.isPoolPreparedStatements()) { - PoolablePreparedStatement poolableStatement = holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + stmt = holder.getStatementPool().get(key); } - PreparedStatement stmt = null; - try { - stmt = conn.prepareStatement(sql, columnNames); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareStatement(sql, columnNames); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); + PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -318,28 +286,24 @@ public class PoolableConnection implements PooledConnection, Connection { public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { checkOpen(); + PreparedStatement stmt = null; + PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M6); if (holder.isPoolPreparedStatements()) { - PoolablePreparedStatement poolableStatement = holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + stmt = holder.getStatementPool().get(key); } - PreparedStatement stmt = null; - try { - stmt = conn.prepareStatement(sql, autoGeneratedKeys); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareStatement(sql, autoGeneratedKeys); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); + PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -354,27 +318,23 @@ public class PoolableConnection implements PooledConnection, Connection { PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_1); - if (holder.isPoolPreparedStatements()) { - PoolableCallableStatement poolableStatement = (PoolableCallableStatement) holder.getStatementPool().get(key); + CallableStatement stmt = null; - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + if (holder.isPoolPreparedStatements()) { + stmt = (CallableStatement) holder.getStatementPool().get(key); } - CallableStatement stmt = null; - try { - stmt = conn.prepareCall(sql); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareCall(sql); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql); + PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -386,28 +346,24 @@ public class PoolableConnection implements PooledConnection, Connection { int resultSetHoldability) throws SQLException { checkOpen(); + CallableStatement stmt = null; + PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_2); if (holder.isPoolPreparedStatements()) { - PoolableCallableStatement poolableStatement = (PoolableCallableStatement) holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + stmt = (CallableStatement) holder.getStatementPool().get(key); } - CallableStatement stmt = null; - try { - stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql); + PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql); holder.addTrace(rtnVal); @@ -418,29 +374,24 @@ public class PoolableConnection implements PooledConnection, Connection { public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); + CallableStatement stmt = null; + PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_3); if (holder.isPoolPreparedStatements()) { - - PoolableCallableStatement poolableStatement = (PoolableCallableStatement) holder.getStatementPool().get(key); - - if (poolableStatement != null) { - poolableStatement.setPoolableConnection(this); - poolableStatement.setClosed(false); - holder.addTrace(poolableStatement); - return poolableStatement; - } + stmt = (CallableStatement) holder.getStatementPool().get(key); } - CallableStatement stmt = null; - try { - stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency); - } catch (SQLException ex) { - handleException(ex); + if (stmt == null) { + try { + stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency); + } catch (SQLException ex) { + handleException(ex); + } } holder.getDataSource().initStatement(stmt); - CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql); + PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql); holder.addTrace(rtnVal); return rtnVal; @@ -552,14 +503,14 @@ public class PoolableConnection implements PooledConnection, Connection { handleException(ex); } } - + protected void transactionRecord(String sql) throws SQLException { if (transactionInfo == null && (!conn.getAutoCommit())) { DruidAbstractDataSource dataSource = holder.getDataSource(); dataSource.incrementStartTransactionCount(); transactionInfo = new TransactionInfo(dataSource.createTransactionId()); } - + if (transactionInfo != null) { transactionInfo.getSqlList().add(sql); } @@ -597,7 +548,7 @@ public class PoolableConnection implements PooledConnection, Connection { if (transactionInfo == null) { return; } - + checkOpen(); DruidAbstractDataSource dataSource = holder.getDataSource(); @@ -643,7 +594,7 @@ public class PoolableConnection implements PooledConnection, Connection { long transactionMillis = currentTimeMillis - transactionInfo.getStartTimeMillis(); dataSource.getTransactionHistogram().recode(transactionMillis); - dataSource.logTransaction( transactionInfo); + dataSource.logTransaction(transactionInfo); transactionInfo = null; } diff --git a/src/main/java/com/alibaba/druid/pool/PoolablePreparedStatement.java b/src/main/java/com/alibaba/druid/pool/PoolablePreparedStatement.java index aa860dacf4..4a9e16af8f 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolablePreparedStatement.java +++ b/src/main/java/com/alibaba/druid/pool/PoolablePreparedStatement.java @@ -47,12 +47,60 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep private final PreparedStatementKey key; private final String sql; + private int defaultMaxFieldSize; + private int defaultMaxRows; + private int defaultQueryTimeout; + private int defaultFetchDirection; + private int defaultFetchSize; + private int currentMaxFieldSize; + private int currentMaxRows; + private int currentQueryTimeout; + private int currentFetchDirection; + private int currentFetchSize; + public PoolablePreparedStatement(PoolableConnection conn, PreparedStatement stmt, PreparedStatementKey key, - String sql){ + String sql) throws SQLException{ super(conn, stmt); this.stmt = stmt; this.key = key; this.sql = sql; + + // Remember the defaults + defaultMaxFieldSize = stmt.getMaxFieldSize(); + defaultMaxRows = stmt.getMaxRows(); + defaultQueryTimeout = stmt.getQueryTimeout(); + defaultFetchDirection = stmt.getFetchDirection(); + defaultFetchSize = stmt.getFetchSize(); + currentMaxFieldSize = defaultMaxFieldSize; + currentMaxRows = defaultMaxRows; + currentQueryTimeout = defaultQueryTimeout; + currentFetchDirection = defaultFetchDirection; + currentFetchSize = defaultFetchSize; + } + + public void setFetchSize(int rows) throws SQLException { + currentFetchSize = rows; + super.setFetchSize(rows); + } + + public void setFetchDirection(int direction) throws SQLException { + currentFetchDirection = direction; + super.setFetchDirection(direction); + } + + public void setMaxFieldSize(int max) throws SQLException { + currentMaxFieldSize = max; + super.setMaxFieldSize(max); + } + + public void setMaxRows(int max) throws SQLException { + currentMaxRows = max; + super.setMaxRows(max); + } + + public void setQueryTimeout(int seconds) throws SQLException { + currentQueryTimeout = seconds; + super.setQueryTimeout(seconds); } public String getSql() { @@ -77,6 +125,28 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep return; } + // Reset the defaults + if (defaultMaxFieldSize != currentMaxFieldSize) { + stmt.setMaxFieldSize(defaultMaxFieldSize); + currentMaxFieldSize = defaultMaxFieldSize; + } + if (defaultMaxRows != currentMaxRows) { + stmt.setMaxRows(defaultMaxRows); + currentMaxRows = defaultMaxRows; + } + if (defaultQueryTimeout != currentQueryTimeout) { + stmt.setQueryTimeout(defaultQueryTimeout); + currentQueryTimeout = defaultQueryTimeout; + } + if (defaultFetchDirection != currentFetchDirection) { + stmt.setFetchDirection(defaultFetchDirection); + currentFetchDirection = defaultFetchDirection; + } + if (defaultFetchSize != currentFetchSize) { + stmt.setFetchSize(defaultFetchSize); + currentFetchSize = defaultFetchSize; + } + conn.closePoolableStatement(this); } @@ -91,7 +161,7 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep @Override public ResultSet executeQuery() throws SQLException { checkOpen(); - + transactionRecord(sql); try { @@ -109,7 +179,7 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep @Override public int executeUpdate() throws SQLException { checkOpen(); - + transactionRecord(sql); try { @@ -343,7 +413,7 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep @Override public boolean execute() throws SQLException { checkOpen(); - + transactionRecord(sql); try { @@ -363,10 +433,10 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep throw checkException(t); } } - + public int[] executeBatch() throws SQLException { transactionRecord(sql); - + return super.executeBatch(); } diff --git a/src/main/java/com/alibaba/druid/pool/PoolableStatement.java b/src/main/java/com/alibaba/druid/pool/PoolableStatement.java index 30eed98a9d..e22e0b8bfe 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolableStatement.java +++ b/src/main/java/com/alibaba/druid/pool/PoolableStatement.java @@ -126,7 +126,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement { } @Override - public final int getMaxFieldSize() throws SQLException { + public int getMaxFieldSize() throws SQLException { checkOpen(); try { @@ -137,7 +137,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement { } @Override - public final void setMaxFieldSize(int max) throws SQLException { + public void setMaxFieldSize(int max) throws SQLException { checkOpen(); try { @@ -159,7 +159,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement { } @Override - public final void setMaxRows(int max) throws SQLException { + public void setMaxRows(int max) throws SQLException { checkOpen(); try { @@ -192,7 +192,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement { } @Override - public final void setQueryTimeout(int seconds) throws SQLException { + public void setQueryTimeout(int seconds) throws SQLException { checkOpen(); try { @@ -298,7 +298,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement { } @Override - public final void setFetchDirection(int direction) throws SQLException { + public void setFetchDirection(int direction) throws SQLException { checkOpen(); try { @@ -320,7 +320,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement { } @Override - public final void setFetchSize(int rows) throws SQLException { + public void setFetchSize(int rows) throws SQLException { checkOpen(); try { diff --git a/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java b/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java index ce8e8c4917..1e3878a22a 100644 --- a/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java +++ b/src/main/java/com/alibaba/druid/pool/PreparedStatementPool.java @@ -15,9 +15,8 @@ */ package com.alibaba.druid.pool; -import java.util.ArrayList; +import java.sql.PreparedStatement; import java.util.HashMap; -import java.util.List; import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey; @@ -26,46 +25,22 @@ import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey; */ public class PreparedStatementPool { - private HashMap> map = new HashMap>(); + private HashMap map = new HashMap(); public static enum MethodType { M1, M2, M3, M4, M5, M6, Precall_1, Precall_2, Precall_3 } - public PoolablePreparedStatement get(PreparedStatementKey key) { - List list = map.get(key); - - if (list == null) { - list = new ArrayList(); - map.put(key, list); - - return null; - } - - int size = list.size(); - - if (size == 0) { - return null; - } - - PoolablePreparedStatement last = list.remove(size - 1); - - return last; + public PreparedStatement get(PreparedStatementKey key) { + return map.remove(key); } public void put(PoolablePreparedStatement poolableStatement) { PreparedStatementKey key = poolableStatement.getKey(); - List list = map.get(key); - - if (list == null) { - list = new ArrayList(); - map.put(key, list); - } - - list.add(poolableStatement); + map.put(key, poolableStatement.getRawPreparedStatement()); } - public HashMap> getMap() { + public HashMap getMap() { return map; } diff --git a/src/main/java/com/alibaba/druid/sql/parser/SQLExprParser.java b/src/main/java/com/alibaba/druid/sql/parser/SQLExprParser.java index 7b26204b26..61af34ad86 100644 --- a/src/main/java/com/alibaba/druid/sql/parser/SQLExprParser.java +++ b/src/main/java/com/alibaba/druid/sql/parser/SQLExprParser.java @@ -115,7 +115,7 @@ public class SQLExprParser extends SQLParser { } public final SQLExpr multiplicative() throws ParserException { - SQLExpr expr = bitXor(); + SQLExpr expr = primary(); return multiplicativeRest(expr); } @@ -673,7 +673,7 @@ public class SQLExprParser extends SQLParser { } public final SQLExpr equality() throws ParserException { - SQLExpr expr = bitOr(); + SQLExpr expr = shift(); return equalityRest(expr); } @@ -681,14 +681,14 @@ public class SQLExprParser extends SQLParser { SQLExpr rightExp; if (lexer.token() == Token.EQ) { lexer.nextToken(); - rightExp = bitOr(); + rightExp = shift(); rightExp = equalityRest(rightExp); expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp); } else if (lexer.token() == Token.BANGEQ) { lexer.nextToken(); - rightExp = bitOr(); + rightExp = shift(); rightExp = equalityRest(rightExp); diff --git a/src/main/java/com/alibaba/druid/stat/JdbcSqlStat.java b/src/main/java/com/alibaba/druid/stat/JdbcSqlStat.java index aa768d690b..cbde4db563 100644 --- a/src/main/java/com/alibaba/druid/stat/JdbcSqlStat.java +++ b/src/main/java/com/alibaba/druid/stat/JdbcSqlStat.java @@ -335,7 +335,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.DATE, SimpleType.STRING, SimpleType.STRING // - , new ArrayType(1, SimpleType.LONG) + , new ArrayType(SimpleType.LONG, true) }; String[] indexNames = { @@ -368,7 +368,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean { "DbType", "URL" // - , "ExecuteCountHistogram"}; + , "Histogram"}; String[] indexDescriptions = indexNames; COMPOSITE_TYPE = new CompositeType("SqlStatistic", "Sql Statistic", indexNames, indexDescriptions, indexTypes); @@ -421,7 +421,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean { map.put("DbType", dbType); map.put("URL", null); - map.put("ExecuteCountHistogram", this.histogram.toArray()); + map.put("Histogram", this.histogram.toArray()); return map; } diff --git a/src/test/java/com/alibaba/druid/bvt/pool/TestClose_1.java b/src/test/java/com/alibaba/druid/bvt/pool/TestClose_1.java index ed24317737..227895ac7a 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/TestClose_1.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/TestClose_1.java @@ -7,6 +7,7 @@ import java.sql.ResultSet; import junit.framework.Assert; import junit.framework.TestCase; +import com.alibaba.druid.mock.MockStatement; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.stat.DruidDataSourceStatManager; @@ -38,9 +39,9 @@ public class TestClose_1 extends TestCase { Assert.assertEquals(true, rs.isClosed()); PreparedStatement stmt2 = conn.prepareStatement(sql); - Assert.assertEquals(false, stmt.isClosed()); + Assert.assertEquals(true, stmt.isClosed()); - Assert.assertEquals(stmt, stmt2); + Assert.assertEquals(stmt.unwrap(MockStatement.class), stmt2.unwrap(MockStatement.class)); conn.close(); diff --git a/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java b/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java index 91c0100226..b0e8831389 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java @@ -7,6 +7,7 @@ import java.sql.ResultSet; import junit.framework.Assert; import junit.framework.TestCase; +import com.alibaba.druid.mock.MockStatement; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.stat.DruidDataSourceStatManager; @@ -37,9 +38,9 @@ public class TestClose_2 extends TestCase { Assert.assertEquals(true, rs.isClosed()); CallableStatement stmt2 = conn.prepareCall(sql); - Assert.assertEquals(false, stmt.isClosed()); + Assert.assertEquals(true, stmt.isClosed()); - Assert.assertEquals(stmt, stmt2); + Assert.assertEquals(stmt.unwrap(MockStatement.class), stmt2.unwrap(MockStatement.class)); conn.close(); diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/PreparedStatementKeyTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PreparedStatementKeyTest.java index 1c1f28389f..b2919a6a69 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/PreparedStatementKeyTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PreparedStatementKeyTest.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import org.junit.Assert; +import com.alibaba.druid.mock.MockPreparedStatement; import com.alibaba.druid.pool.PoolablePreparedStatement; import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey; import com.alibaba.druid.pool.PreparedStatementPool; @@ -96,7 +97,7 @@ public class PreparedStatementKeyTest extends TestCase { public void test_contains() throws Exception { PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1); PreparedStatementPool pool = new PreparedStatementPool(); - pool.put(new PoolablePreparedStatement(null, null, k1, null)); + pool.put(new PoolablePreparedStatement(null, new MockPreparedStatement(null, null), k1, null)); Assert.assertTrue(pool.get(k1) != null); Assert.assertTrue(pool.get(k1) == null); } diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest.java index b67c690535..6c4ad3df16 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest.java @@ -47,7 +47,8 @@ public class StatFilterTest extends TestCase { if (url.equals((String) row.get("URL"))) { count++; } - Assert.assertEquals(0L, row.get("ExecuteCount_30_more_Minutes")); + long[] histogram = (long[]) row.get("Histogram"); + Assert.assertEquals(0L, histogram[histogram.length - 1]); } Assert.assertEquals(true, count > 0);