Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question about why EJB instance is single-threaded?  RSS feed

 
Robert Strong
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I'm reading Ed Roman's book of Mastering EJB 3rd edition, in it, he pointed out two reasons for single-threaded EJB instances:

1. it's error-prone to write threadsafe code.

2. having multiple threads of execution makes transaction almost impossible to control by the underlying transaction system.

I don't quite understand the second reason, why it'd make transaction control impossible? could anyone explain to me or give me some kind of examples?

thanks
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the kind of things which take place in a transaction, like beginning a JTA transaction, obtaining a JDBC Connection, doing DB updates, commit and close Connection. If, say, another thread could commit before the first thread is ready to invoke commit, you have a problem.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!