Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using EJBs on a thread  RSS feed

 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web page that gets its data via EJBs. The method controlling data access was poorly designed and retrieves much more data than I need for my page. As a result, response time suffers until it completes. I've been experimenting with retrieving the secondary data accesses on a separate thread so that response time for the user is improved. For compatibility reasons, I cannot separate the primary and secondary data accesses at this time.

First of all, is this a good idea? Are there any problems I should be aware of when accessing data via EJBs on a separate thread (on top of normal threading issues)?

Secondly, I had thought it would be sufficient to just pass the appropriate Context object to the thread class and allow it to retrieve the necessary EJB references. However, that does not seem to work. It appears I actually have to retrieve and pass and EJB home interface to the class. Can someone clarify why passing the Context alone is not enough?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jay Damon:
First of all, is this a good idea? Are there any problems I should be aware of when accessing data via EJBs on a separate thread (on top of normal threading issues)?

Threading in an EJB is prohibited by the J2EE spec and should be discouraged. Your app server may support it in unpredictable ways since it goes against the spec. What layer is creating the thread? It sounds to me like the EJB layer, but I'm not sure.


Can someone clarify why passing the Context alone is not enough?

The EJB container cleans up the Context when the original bean is completed. After that, the threads no longer have a valid context.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!