Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can different threads sharing the same Hibernate session?

 
Chip Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have been chasing down a problem that appears to be a deadly embrace between a database and Java locks. We have a core dump that appears to show a connection being shared between two threads. This makes no sense to us since we are using JTA with Hibernate (V3.2 getCurrentSession()). Our understanding is that each transaction would be bound to a single Hibernate-session and JDBC connection.

We are hoping that someone could advice on a several points:
1. Are we correct that a JDBC connection would not be shared by two different threads (in a typical j2ee environment)?
2. Are we correct in our reading of the Core dump? (see below).
3. If we are correct about #1 and #2, would it suggest a problem with Hibernate, or is it more likely that there is an issue with our configuration and/or code?

Many thanks for any thoughts on this.

Here are the locks we see in the core dump…

3LKMONOBJECT oracle/jdbc/driver/T4CConnection@DAE6BFA0/DAE6BFAC: Flat locked by "WebContainer : 51" (0x0B81F700), entry count 1
3LKWAITERQ Waiting to enter:
3LKWAITER "WebContainer : 0" (0x0AAD0000)
3LKWAITER "WebContainer : 5" (0xD0E77600)
3LKWAITER "WebContainer : 58" (0x0AA5FA00)
3LKWAITER "WebContainer : 17" (0x0AA5FE00)

We see Threads 0,5,58 and 17 waiting on the T4CConnection object that is locked by thread 51.

When we look at the (top of the) stack trace for Thread 51, we see that it is waiting on a response from the server (socket read). When we look at the database, we see several sessions blocked with a transaction lock. Therad 51 is almost certianlly one of them.

Here is part of the stack trace for Thread 51...

3XMTHREADINFO "WebContainer : 51" (TID:0x0B81F700, sys_thread_t:0x0C4FB648, state:R, native ID:0x000047AF) prio=5
4XESTACKTRACE at java/net/SocketInputStream.socketRead0(Native Method)
4XESTACKTRACE at java/net/SocketInputStream.read(SocketInputStream.java:155(Compiled Code))
4XESTACKTRACE at oracle/net/ns/Packet.receive(Bytecode PC:31(Compiled Code))
4XESTACKTRACE at oracle/net/ns/DataPacket.receive(Bytecode PC:1(Compiled Code))
4XESTACKTRACE at oracle/net/ns/NetInputStream.getNextPacket(Bytecode PC:1(Compiled Code))
4XESTACKTRACE at oracle/net/ns/NetInputStream.read(Bytecode PC:33(Compiled Code))
4XESTACKTRACE at oracle/net/ns/NetInputStream.read(Bytecode PC:5(Compiled Code))
4XESTACKTRACE at oracle/net/ns/NetInputStream.read(Bytecode PC:5(Compiled Code))
4XE
….(more stack trace deleted)

Threads 0 0,5,58 and 17 are all trying to create a prepared statement, apparently on the same connection. Below is the start of the stack trace for thread 0.

3XMTHREADINFO "WebContainer : 0" (TID:0x0AAD0000, sys_thread_t:0x0AA5660C, state:B, native ID:0x000057F9) prio=5
4XESTACKTRACE at oracle/jdbc/OracleConnectionWrapper.prepareStatement(OracleConnectionWrapper.java:189(Compiled Code))
4XESTACKTRACE at com/ibm/ws/rsadapter/jdbc/WSJdbcConnection.pmiPrepareStatement(WSJdbcConnection.java:1807(Compiled Code))
4XESTACKTRACE at com/ibm/ws/rsadapter/jdbc/WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2046(Compiled Code))
4XESTACKTRACE at com/ibm/ws/rsadapter/jdbc/WSJdbcConnection.prepareStatement(WSJdbcConnection.java:1998(Compiled Code))
4XESTACKTRACE at org/hibernate/jdbc/AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497(Compiled Code))
4XESTACKTRACE at org/hibernate/jdbc/AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415(Compiled Code))
4XESTACKTRACE at org/hibernate/jdbc/AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139(Compiled Code))
4XESTACKTRACE at org/hibernate/loader/Loader.prepareQueryStatement(Loader.java:1560(Compiled Code))
4XESTACKTRACE at org/hibernate/loader/Loader.doQuery(Loader.java:661(Compiled Code))
4
….(more stack trace deleted)


 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites
https://forum.hibernate.org/viewtopic.php?f=1&t=1023826


1. Are we correct that a JDBC connection would not be shared by two different threads (in a typical j2ee environment)?

I would say not typically The hibernate documentation has a wealth of documentation on how sessions work with JTA. The JTA spec does say the following though:
"Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.

2. Are we correct in our reading of the Core dump? (see below).

I don't have that depth of knowledge with Websphere. You could try posting just that question in the Websphere forum though and see if anyone else knows.

3. If we are correct about #1 and #2, would it suggest a problem with Hibernate, or is it more likely that there is an issue with our configuration and/or code?


Almost certainly with your configuration (hibernate/websphere ) or code. You have to consider the number of enterprise applications running with this configuration. While it possible you have encountered a bug it is by far more likely to be the other.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic