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

Regarding SessionFactory object and second-Level Cache

 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I have doubt regarding SessionFactory object and second-Level Cache.
SessionFactory object is thread-safe and shared by all application threads.
My Question is How it will be thread-safe in Multithreaded Environment if multiple threads access the same SessionFactory object?
and why we need go for second-Level Cache mechanism?

please correct me if I'm wrong.
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public interface SessionFactory extends Referenceable, Serializable

Creates Sessions. Usually an application has a single SessionFactory. Threads servicing client requests obtain Sessions from the factory.

Implementors must be threadsafe.

SessionFactorys are immutable. The behaviour of a SessionFactory is controlled by properties supplied at configuration time. These properties are defined on Environment.

2nd level you should be used when you need high performance with less number of database hits.
it can be used with Single VM or clustered VM's.
Same pbject can be shared across different vms.
 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Para wrote:SessionFactorys are immutable.


Hi Ram
Thanks For your reply.

I have one more doubt.If SessionFactory is immutable.Will you get any Data Corruption if Multiple threads access?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think it through: the definition of immutable is it is unchanging. Do you think an unchanging thing can become corrupted by multiple threads accessing it?
 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry paul,

I forgot The point(i.e immutable) and Thanks for your reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic