- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我读了很多帖子
5 things you don't know about synchronization
Avoid synchronized this
Synchronized method access in java
我对可能发生死锁的可能情况有点熟悉,但我很惊讶地在下面的代码中看到死锁,到底是什么导致了它,???对我来说是一个大问号???
我的代码:
public class MySqlDB
{
private Connection connection = null;
//private Statement statement = null;
private DataSource datasource = null;
private Object lockOnTransactionSql = new Object();
public MySqlDB(String username, String password)
{
PoolProperties p = new PoolProperties();
p.setUrl("jdbc:mysql://localhost:3306/test?autoReconnect=true");
p.setUsername(username);
p.setPassword(password);
p.setDriverClassName("org.mariadb.jdbc.Driver");
datasource = new DataSource();
datasource.setPoolProperties(p);
}
private synchronized Statement getStatement() throws SQLException //THIS FUNCTION SOME TIME GOES IN LOCK MODE AND WAITING FOR HOURS BUT IT NEVER RETRUNS
{
if(connection==null || connection.isClosed())
{
if(connection != null)
connection.close();
connection = datasource.getConnection();
}
return connection.createStatement();
}
public void ProcessTransactionSql(ArrayList<String> queries) throws Exception
{
synchronized (lockOnTransactionSql)
{
Statement statement = null;
Connection connection = null;
try
{
connection = datasource.getConnection();
connection.setAutoCommit(false);
statement = connection.createStatement();
for (String query : queries)
statement.execute(query);
connection.commit();
}
catch (Exception e)
{
connection.rollback();
throw e;
}
finally
{
connection.setAutoCommit(true);
statement.close();
connection.close();
}
}
}
public ResultSet ProcessSelectSql(String sql) throws Exception
{
return getStatement().executeQuery(sql);
}
public boolean ProcessUpdateSql(String sql) throws Exception
{
Statement st = null;
Connection connection = null;
try
{
connection = datasource.getConnection();
st = connection.createStatement();
return st.execute(sql);
}
finally
{
st.close();
connection.close();
}
}
}
在上面的代码中,ProcessSelectSql
、ProcessTransactionSql
和 ProcessUpdateSql
是从多个函数并行调用的函数,但在 Linux 计算机上运行几个小时或几天后,就会发生死锁。
观察到 getStatement
是从不返回语句的函数。
我的问题是可能发生死锁的原因是什么
需要强调的要点:
test
和相同的类 MySqlDB
执行各种操作对数据库的操作。编辑我能够重新创建死锁并使用命令java -3 pid_of_java_jar
来获取堆栈跟踪,它是
"RMI TCP Connection(597)-127.0.0.1" #160957 daemon prio=5 os_prio=0 tid=0x00007f5c6400e800 nid=0x9405 waiting for monitor entry [0x00007f5cd6a98000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFileDetails(SourceFile:3324)
at com.mytest.service.RMIHandler.GetFileDetails(SourceFile:726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"RMI TCP Connection(590)-127.0.0.1" #160952 daemon prio=5 os_prio=0 tid=0x00007f5c64005000 nid=0xb9dd waiting for monitor entry [0x00007f5cd7ffc000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFileDetails(SourceFile:3324)
at com.mytest.service.RMIHandler.GetFileDetails(SourceFile:726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"RMI TCP Connection(589)-127.0.0.1" #160951 daemon prio=5 os_prio=0 tid=0x00007f5c64001000 nid=0xa172 waiting for monitor entry [0x00007f5cdc434000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFileDetails(SourceFile:3324)
at com.mytest.service.RMIHandler.GetFileDetails(SourceFile:726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"RMI TCP Connection(588)-127.0.0.1" #160950 daemon prio=5 os_prio=0 tid=0x00007f5c6400c000 nid=0x6809 waiting for monitor entry [0x00007f5cd6c9a000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFileDetails(SourceFile:3324)
at com.mytest.service.RMIHandler.GetFileDetails(SourceFile:726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"RMI TCP Connection(534)-127.0.0.1" #160897 daemon prio=5 os_prio=0 tid=0x00007f5c64008800 nid=0xecc6 waiting for monitor entry [0x00007f5cd6997000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFileDetails(SourceFile:3324)
at com.mytest.service.RMIHandler.GetFileDetails(SourceFile:726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"RMI TCP Connection(435)-127.0.0.1" #160801 daemon prio=5 os_prio=0 tid=0x00007f5c64002800 nid=0x94c1 waiting for monitor entry [0x00007f5cd6b99000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFileDetails(SourceFile:3324)
at com.mytest.service.RMIHandler.GetFileDetails(SourceFile:726)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"RMI TCP Connection(431)-127.0.0.1" #160793 daemon prio=5 os_prio=0 tid=0x00007f5c64007800 nid=0xfc2e waiting for monitor entry [0x00007f5cd7efb000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.DeviceDB.GetDeviceId(SourceFile:565)
at com.mytest.service.RMIHandler.ProcessSyncCycle(SourceFile:698)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$65(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1295046191.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"Thread-34026" #102332 daemon prio=5 os_prio=0 tid=0x00007f5c28006000 nid=0x7817 waiting for monitor entry [0x00007f5cd6d9d000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.AreaDB.GetDeviceArea(SourceFile:236)
at com.mytest.service.ListMgr.SubmitJob(SourceFile:187)
at com.mytest.service.ListMgr$2.run(SourceFile:137)
at java.lang.Thread.run(Thread.java:745)
"Java2D Disposer" #37059 daemon prio=10 os_prio=0 tid=0x00007f5c2401a000 nid=0x4bbf in Object.wait() [0x00007f5cdccac000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000006cc9ffd18> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at sun.java2d.Disposer.run(Disposer.java:148)
at java.lang.Thread.run(Thread.java:745)
"Thread-49" #146 daemon prio=5 os_prio=0 tid=0x00007f5c6c05e800 nid=0xd30c waiting for monitor entry [0x00007f5cdc8a9000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.UserDB.GetUsers(SourceFile:718)
at com.mytest.service.CService.ProcessJob(SourceFile:553)
at com.mytest.service.CService.ProcessJob(SourceFile:648)
at com.mytest.service.ListMgr.run(SourceFile:98)
at java.lang.Thread.run(Thread.java:745)
"Thread-48" #145 daemon prio=5 os_prio=0 tid=0x00007f5c6c03b800 nid=0xd30b waiting for monitor entry [0x00007f5cddaba000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
- waiting to lock <0x00000006d5c4d808> (a java.io.BufferedInputStream)
at org.mariadb.jdbc.internal.common.packet.buffer.ReadUtil.readFully(ReadUtil.java:82)
at org.mariadb.jdbc.internal.common.packet.buffer.ReadUtil.readFully(ReadUtil.java:92)
at org.mariadb.jdbc.internal.common.packet.RawPacket.nextPacket(RawPacket.java:82)
at org.mariadb.jdbc.internal.common.packet.SyncPacketFetcher.getRawPacket(SyncPacketFetcher.java:67)
at org.mariadb.jdbc.internal.common.queryresults.StreamingSelectResult.next(StreamingSelectResult.java:85)
at org.mariadb.jdbc.internal.common.queryresults.CachedSelectResult.createCachedSelectResult(CachedSelectResult.java:77)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.createQueryResult(MySQLProtocol.java:815)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.getResult(MySQLProtocol.java:951)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:982)
at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:280)
- locked <0x00000006d5c4d0b8> (a org.mariadb.jdbc.internal.mysql.MySQLProtocol)
at org.mariadb.jdbc.MySQLStatement.executeQuery(MySQLStatement.java:301)
at org.mariadb.jdbc.MySQLStatement.executeQuery(MySQLStatement.java:360)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFilesToProcess(SourceFile:1880)
at com.mytest.service.CService.SubmitJob(SourceFile:1093)
at com.mytest.service.ListMgr$2.run(SourceFile:137)
at java.lang.Thread.run(Thread.java:745)
"Thread-15" #46 prio=5 os_prio=0 tid=0x00007f5c30001000 nid=0xac80 waiting on condition [0x00007f5cdcbab000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006d5c4daa0> (a java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
at java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock.lock(ReentrantReadWriteLock.java:943)
at org.apache.tomcat.jdbc.pool.PooledConnection.lock(PooledConnection.java:609)
at org.apache.tomcat.jdbc.pool.ConnectionPool.returnConnection(ConnectionPool.java:893)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:100)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:61)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.invoke(ConnectionState.java:153)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.TrapException.invoke(TrapException.java:41)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
at com.sun.proxy.$Proxy0.close(Unknown Source)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:37)
- locked <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.UserDB.GetUsers(SourceFile:718)
at com.mytest.service.TService.a(SourceFile:38)
at com.mytest.service.TService$2.run(SourceFile:301)
at java.lang.Thread.run(Thread.java:745)
"Thread-14" #45 daemon prio=5 os_prio=0 tid=0x00007f5c5000d800 nid=0xa363 waiting for monitor entry [0x00007f5cdd5b5000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.DeviceDB.GetDeviceId(SourceFile:565)
at com.mytest.service.MDeviceMap.a(SourceFile:41)
at com.mytest.service.MDeviceMap$1.run(SourceFile:113)
at java.lang.Thread.run(Thread.java:745)
"Thread-11" #37 prio=5 os_prio=0 tid=0x00007f5c6c03e000 nid=0x1dd4 waiting for monitor entry [0x00007f5cdcdad000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.FileDB.GetFilePath(SourceFile:3928)
at com.mytest.service.SService.d(SourceFile:712)
at com.mytest.service.SService.a(SourceFile:129)
at com.mytest.service.SService.a(SourceFile:38)
at com.mytest.service.SService$1.run(SourceFile:102)
at java.lang.Thread.run(Thread.java:745)
"Thread-10" #36 prio=5 os_prio=0 tid=0x00007f5c6c03f000 nid=0x1dca waiting for monitor entry [0x00007f5cdceae000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mytest.dbhelper.MySqlDB.getStatement(SourceFile:32)
- waiting to lock <0x00000006c5e79580> (a java.lang.Object)
at com.mytest.dbhelper.MySqlDB.ProcessSelectSql(SourceFile:466)
at com.mytest.filemanager.DeviceDB.GetDevices(SourceFile:1674)
at com.mytest.service.TService.ThService(SourceFile:171)
at com.mytest.service.TService$1.run(SourceFile:135)
at java.lang.Thread.run(Thread.java:745)
"PoolCleaner[1550089733:1450166181974]" #12 daemon prio=5 os_prio=0 tid=0x00007f5cfc625800 nid=0x1d94 runnable [0x00007f5cde9c1000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
- locked <0x00000006d5c4d808> (a java.io.BufferedInputStream)
at org.mariadb.jdbc.internal.common.packet.buffer.ReadUtil.readFully(ReadUtil.java:82)
at org.mariadb.jdbc.internal.common.packet.buffer.ReadUtil.readFully(ReadUtil.java:92)
at org.mariadb.jdbc.internal.common.packet.RawPacket.nextPacket(RawPacket.java:82)
at org.mariadb.jdbc.internal.common.packet.SyncPacketFetcher.getRawPacket(SyncPacketFetcher.java:67)
at org.mariadb.jdbc.internal.mysql.packet.MySQLRowPacket.getRow(MySQLRowPacket.java:86)
at org.mariadb.jdbc.internal.common.queryresults.StreamingSelectResult.next(StreamingSelectResult.java:107)
at org.mariadb.jdbc.internal.common.queryresults.StreamingSelectResult.close(StreamingSelectResult.java:123)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.skip(MySQLProtocol.java:728)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.close(MySQLProtocol.java:779)
at org.mariadb.jdbc.MySQLConnection.close(MySQLConnection.java:249)
at org.apache.tomcat.jdbc.pool.PooledConnection.disconnect(PooledConnection.java:331)
at org.apache.tomcat.jdbc.pool.PooledConnection.release(PooledConnection.java:490)
at org.apache.tomcat.jdbc.pool.ConnectionPool.release(ConnectionPool.java:581)
at org.apache.tomcat.jdbc.pool.ConnectionPool.abandon(ConnectionPool.java:540)
at org.apache.tomcat.jdbc.pool.ConnectionPool.checkAbandoned(ConnectionPool.java:958)
at org.apache.tomcat.jdbc.pool.ConnectionPool$PoolCleaner.run(ConnectionPool.java:1347)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
"VM Periodic Task Thread" os_prio=0 tid=0x00007f5cfc22a800 nid=0x1d92 waiting on condition
JNI global references: 478
Heap
PSYoungGen total 181760K, used 117101K [0x000000076c980000, 0x000000077e500000, 0x00000007c0000000)
eden space 180736K, 64% used [0x000000076c980000,0x0000000773bdb500,0x0000000777a00000)
from space 1024K, 0% used [0x0000000777a00000,0x0000000777a00000,0x0000000777b00000)
to space 54784K, 0% used [0x000000077af80000,0x000000077af80000,0x000000077e500000)
ParOldGen total 443392K, used 274009K [0x00000006c5c00000, 0x00000006e0d00000, 0x000000076c980000)
object space 443392K, 61% used [0x00000006c5c00000,0x00000006d6796760,0x00000006e0d00000)
Metaspace used 24224K, capacity 24486K, committed 24832K, reserved 1071104K
class space used 2128K, capacity 2213K, committed 2304K, reserved 1048576K
最佳答案
驻留在两个不同 jar 中的两个不同应用程序正在访问 getStatement() 方法,该方法又创建一个作为 MySqlDB 实例字段创建的 Connection 对象。一般来说,我们应该避免共享连接,并为每个请求从池中获取连接,并在工作完成后关闭连接。您还可以尝试使用新的锁 API 并利用锁公平性和超时来避免死锁。是的,需要处理锁超时异常。
关于java - 同步方法与mysql连接池创建死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34058943/
最近,我们将专用 SQL 池部署到生产中的 Synapse 工作区。在开发中,我们可以访问无服务器 SQL 池和专用 SQL 池。但是,在生产中,我们可以访问无服务器 SQL 池,但无法访问专用 SQ
假设您从一个项目公开 WCF 服务,并使用“添加服务引用”(在本例中为 Framework 3.5 WPF 应用程序)在另一个项目中使用它。 当您重新实例化 ClientBase 派生代理时,Clie
我有一个函数,它使用 multiprocessing.Pool 并行处理一个数据集中的所有数据。 from multiprocessing import Pool ... def func():
我正在尝试使用进程对象在 python 中使用工作池。每个 worker (一个进程)进行一些初始化(花费大量时间),传递一系列作业(理想情况下使用 map()),并返回一些东西。除此之外,不需要任何
我是软件工程师,最近我构建了我的 Linux 机器,想探索更多系统管理员类型的任务。我已经探索并阅读了很多关于 ZFS 的内容,但我越来越困惑,因为每篇文章对它的描述都不一样。 Everything
我有 zfs 池: $ sudo zpool status lxd pool: lxd state: ONLINE scan: none requested config: NAME
我有一个基于 Actor 的项目,对于其中的一部分,我必须使用一些接收消息的 Actor ,然后一个 Actor 分别分配给每个请求,每个 Actor 负责执行其消息请求,所以我需要类似线程的东西我的
我已经使用 QEMU 模拟器成功地将 FreeBSD 安装到原始图像文件中。我已经使用 ZFS 文件系统 (ZFS POOL) 格式化了图像文件。 使用下面的命令我已经成功地挂载了准备好由 zpool
我正在使用 multiprocessor.Pool并行处理一些文件。该代码等待接收文件,然后使用 Pool.apply_async 将该文件发送给工作人员。 ,然后处理文件。 这段代码应该一直在运行,
我正在使用带有光滑的 Bonecp 数据源。并发现池包含关闭的连接所以我总是遇到这个异常 java.sql.SQLException: Connection is closed! at com
我有apartment gem的 Multi-Tenancy Rails应用程序,我可以使用apartment-sidekiq在每个工作程序中成功切换数据库租户。但是,sidekiq worker 正
ZFS 池可能由数据集(文件系统、快照等)或卷组成。 ZFS 卷就像 block 设备,但我不明白池和文件系统之间的区别。当我通过 zpool create pool1 sda sdb sdc 创建
我在 docker 容器上运行了 airflow。我正在使用 airflow 2.0.2 版。 我知道我实际上可以通过 UI 创建池。但我正在寻找一种通过 pools.json 文件在 docker
我在tomcat中有一个jdbc池,用于建立数据库连接。我在使用后没有显式关闭连接对象。我的“maxActive”参数设置为100。应用程序运行了一段时间,但随后失败进行数据库查询。它会等待无限时间来
阅读 PostgreSQL 文档 here我读了以下内容: As well, connections requested for users other than the default config
我在 docker 容器上运行了 airflow。我正在使用 airflow 2.0.2 版。 我知道我实际上可以通过 UI 创建池。但我正在寻找一种通过 pools.json 文件在 docker
我正在读取一个大的 URL 文件并向服务发出请求。该请求由返回 ListenableFuture 的客户端执行。现在我想保留一个 ListenableFuture 池,例如最多同时执行 N 个 Fut
我想使用队列来保存结果,因为我希望消费者(串行而不是并行)在工作人员产生结果时处理工作人员的结果。 现在,我想知道为什么以下程序挂起。 import multiprocessing as mp imp
我正在开发一个单页应用程序,目前正在构建一个 JQuery、ajax 函数,以便我的所有调用都能通过。 对于一个典型的页面,我可能有 3 个 ajax 调用。我的想法是,如果用户互联网出去将这些 aj
我有一个单位类及其一些子类(弓箭手、剑客等)。我怎样才能创建一个回收所有单元类型子类的池? 最佳答案 这是不可能的,因为池只能包含一种特定类型的对象。否则你可能会遇到这样的情况: Pool unitP
我是一名优秀的程序员,十分优秀!