So here's my understand how Hibernate uses the 2nd level cache (disclaimer: I'm 
not a Hibernate expert).
And I haven't read the docs yet...

- 1st level cache is per Session. This is an Object-level cache
- 2nd level is per VM, shared by all Sessions. This is a row-based cache
- When an object is loaded, the corresponding rows are loaded from the DB and 
added to the 2nd level cache. Assuming we use JBossCache, these will be 
replicated
(not sure about this point though)
- Then H creates the object in the session cache
- On update (TX commit): H writes to the DB, modified the session cache and (I 
guess) invalidates the 2nd level cache. The invalidate is replicated across the 
cluster.

So, if this is correct, the 2nd level cache (JBossCache) is only read-accessed 
when *any* session in a JVM loads an object for the first time (scope=TX). So 
the session object is valid until TX end. 
When an object is modified, at TX end, the object is written back to the DB and 
invalidated from the 2nd level cache across the cluster.

So reads to JBossCache happen on object-load in any given H Session, writes 
happen on object-modification (at TX end).

So this means that locks are acquired in JBossCache for all reads and writes 
for the duration of TXs. If you use REPEATABLE_READ for JBossCache, then we 
have r/w  lock semantics, ie. concurrent reads are possible. However, if you 
have *one* write in a given TX, all other TXs are locked out until the writing 
TX commits.

So in your case, if you had only reads, you'd be fine. However, there is one 
write, which causes other TXs to block. Can you idntify that write ? If you 
keep that write TX short, then subsequently, all read TXs should be able to 
acquire locks and proceed.

So in your servlet code, if you only do load() methods, you should *never* run 
into lock acquisition problems.


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3863887#3863887

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3863887


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
JBoss-Development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to