-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: synchronize, serialized access and caches
PostPosted: Fri Mar 02, 2007 4:45 am 
Newbie

Joined: Fri Mar 02, 2007 4:32 am
Posts: 5
Location: Munich, Germany
Hallo,

ich habe ein sehr seltsames Verhalten zu dem mir keine Lösung einfällt. Ich habe Hibernate, der innerhalb von synchronize ausgeführt wird. Am besten zeige ich die Logik per Pseudocode:

foo();
synchronize(this) {
beginTransaction();
readData();
deleteTheReadData();
flush();
clearSession();
commitTransaction();
}

Wenn nun zwei Threads sich kreuzen, also während der erste läuft ein zweiter startet, wird der zweite Thread wie erwartet am synchronize(this) geblockt. Wenn der erste Thread nun den synchronisierten Bereich, so startet der zweite Thread.

Dummerweise liefert readData(); die selben (Auch im Sinne von Objekt-ID) Datensätze wie sie der erste Thread bekam. Beim Aufruf von deleteTheReadData() fliegt dann eine Exception, weil es die Daten natürlich nicht mehr gibt. In der Datenbank ist alles wie zu erwarten.

Setze ich nun eine Breakpoint auf foo(), schicke den ersten Thread weiter und lasse den zweiten Thread warten bis der erste Thread durch ist, funktioniert alles wunderbar.

Second-Level-Caches sind deaktiviert, ich kann mir eigentlich nur vorstellen, dass irgendwas mit dem 1st-Level-Cache nicht stimmt. Die Session wird in ThreadLocal gespeichert.

Hat dieses Verhalten schonmal jemand beobachten können? Ich freue mich auf eure Antworten. :-)

Viele Grüße

Christian Kalkhoff

_________________
Christian Kalkhoff
JavaEE Developer
Linux Administrator
http://www.kalkhoff.net


Last edited by ninan on Fri Mar 02, 2007 7:37 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: synchronize, serialisierter Zugriff und die Caches
PostPosted: Fri Mar 02, 2007 4:54 am 
Newbie

Joined: Fri Mar 02, 2007 4:32 am
Posts: 5
Location: Munich, Germany
Hi,

sorry. Just realised I´ve postet to wrong forum. Here is the english translation of my message.

ninan wrote:
Hi,

I see very strange behaviour with Hibernate. I run some Hibernate Code within synchronized block. I will show it using pseudocode:

foo();
synchronize(this) {
beginTransaction();
readData();
deleteTheReadData();
flush();
clearSession();
commitTransaction();
}

If there are two threads the second thread is blocked on reaching synchronize(this). If the first thread leaves the synchronized area, second thread continues.

Now readData() returns the very SAME objecs (even same position on heap) the first thread deleted in its run. Running deleteTheReadData() throws an exception as one might expect.

If I set a breakpoint at foo(), start two threads and continue execution of first thread till it finishes and run thread two afterwards everything works fine.

Second level caches are inactive. I can only imagine there is some problem with the first level cache. The Session is saved in ThreadLocal.

Does anybody has a clue what is going on here?

Best regards

Christian Kalkhoff

_________________
Christian Kalkhoff
JavaEE Developer
Linux Administrator
http://www.kalkhoff.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.