This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multi-thread and EntityManager on SE application  RSS feed

 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm developing Swing application with JPA 2.0 (EclipseLink 2.0.2)
Since it is Java SE application, I can't use injection and/or JNDI

javax.swing.SwingWorker says:
Time-consuming tasks should not be run on the Event Dispatch Thread. Otherwise the application becomes unresponsive.
Swing components should be accessed on the Event Dispatch Thread only.

So, I use SwingWorker for time-consuming database access.
However, I'm not sure whether objects regarding EntityManager is thread-safe, and there are no "container" to manage them.

Question:
1. Can we use EntityManagerFactory object on many threads without explicit synchronize?
2. Can we use EntityManager object (for read-only) on many threads without explicit synchronize?
3. Is it "cheap" to make EntityManager object? (by emf.createEntityManager())
Is it "reasonable" to make EntityManager to invoke only one find operation and close it?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!