-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cache, session, threads - possible pattern
PostPosted: Sat Feb 07, 2004 7:19 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
My application has about 20 threads (takes from pool).

This what I'm thinking about:

1) I use the ThreadLocalSession to associate a session with each thread.

2) I always keep the session open (or should I disconnect() after each RMI request ?) in order to make caching work

3) When the application ends, I have a finalizer in the ThreadLocalSession class that actually closes the session. Or will it close automatically?

Is this good or no good? It seems to work, but I'm not sure if it is the best approach.


Top
 Profile  
 
 Post subject: Re: Cache, session, threads - possible pattern
PostPosted: Sat Feb 07, 2004 7:36 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
My application has about 20 threads (takes from pool).

This what I'm thinking about:

1) I use the ThreadLocalSession to associate a session with each thread.

This is OK.

2) I always keep the session open (or should I disconnect() after each RMI request ?) in order to make caching work

It must be better to use JVM level cache, you dublicate cache per session and your caches are too isolated (session cache is local for transaction)


3) When the application ends, I have a finalizer in the ThreadLocalSession class that actually closes the session. Or will it close automatically?

Close it after transaction.

Think about session as connection wrapper and it must be clear how to manage it (if you know how to manage jdbc resources).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 7:40 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
Thanks for the prompt reply.

Quote:
It must be better to use JVM level cache,


How do I do that? Please elaborate.

Quote:
Close it after transaction.


But then session-level caching doesn't work???

I wan't my objects representing code tables to be cached between invocations. But if I close the session after the request, the cache is empty on the next call!

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 1:22 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Thanks for the prompt reply.

Quote:
It must be better to use JVM level cache,


How do I do that? Please elaborate.

http://www.hibernate.org/hib_docs/refer ... ormance-s3

Quote:
Close it after transaction.


But then session-level caching doesn't work???

I wan't my objects representing code tables to be cached between invocations. But if I close the session after the request, the cache is empty on the next call!

Yes, it is vissible for single thread, multiple threads see different sessions and data in cache (I do not think you want this). Session level is good in transaction, transactions are isolated any way and no synchronization needed for this cache, it must be invalidated after transaction (or placed to the global cache).
As I understand you need global cache to reuse objects in multiple threads and looks like it is trasactional in hibernate.

Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.