• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Entity manager should be thread safe ?  RSS feed

 
Ranch Hand
Posts: 1703
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a question in the free www.examclouds.com mock exam. It asked who is responsible to make sure entity manager is thread safe. The answer is the application is responsible for this.

In JPA Pro (2nd) edition, page 130, chapter 6


While EntityManagerFactgor instances are thread-safe, EntityManager instances are not.


But on p.355 of the same book, chapter 11,


Entity managers and the persistence contexts that they manage are not intended to be accessed by more than one concurrently executing thread. The application cannot expect it to be synchronized and is responsible for ensuring that it stays within the thread that obtains it.



But in the specification , I don't see it says anything whether entity manager is thread-safe or not.
 
Saloon Keeper
Posts: 9378
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. If something isn't explicitly stated, it isn't guaranteed. If a class or interface doesn't mention anything about thread-safety, it isn't thread safe.
 
Himai Minh
Ranch Hand
Posts: 1703
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, the next question from the free examclouds is:


Can entity managers and the persistence contexts that they manage be accessed by several executing threads?


The given answer is No.

But like I mentioned in the previous post, the book says entity manager is not thread safe. That means the entity manager can be accessed by multiple threads.
I think the answer should be Yes.
But it is the application's responsibility to synchronize the entity manager.
 
Stephan van Hulst
Saloon Keeper
Posts: 9378
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Himai Minh wrote:But like I mentioned in the previous post, the book says entity manager is not thread safe. That means the entity manager can be accessed by multiple threads.


If something is NOT thread-safe, it can NOT be used by multiple threads at the same time safely.
 
Himai Minh
Ranch Hand
Posts: 1703
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.
I think the examclouds question is actually asking this:

Can entity managers and the persistence contexts that they manage be accessed by several executing thread safely?


Then, the answer is no.
 
Stephan van Hulst
Saloon Keeper
Posts: 9378
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I understand your point now. Technically, the answer 'yes' would have been correct. It may be worth contacting them about it so they can make the question more precise.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!