dcsimg
A few questions about EJB: scope, synchronized ...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yulin_Zhao
Posted On:   Wednesday, August 20, 2003 02:27 PM

Hi, I'm new to EJB development (only read some books but no experience) but am required to develop some EJB projects(a new one and an old one that doesn't work) right now with no EJB gurus around me. 1. I saw some user-created threads called by (stateless session) EJB's in the old EJB project. The user defined thread (new Thread(someRunnable)...is started when the 1st remote call comes in...??) - according to the books, we should not crate threads within EJB's... so ?? - What is the scope of 'EJB' - if it has some dependencies that is outside the EJB module (e.g: in IBM WSAD5), do we consider the dependencies a part of EJB? So should we impose the limitations defined by the specs for    More>>

Hi,

I'm new to EJB development (only read some books but no experience) but am required to develop some EJB projects(a new one and an old one that doesn't work) right now with no EJB gurus around me.



1. I saw some user-created threads called by (stateless session) EJB's in the old EJB project. The user defined thread (new Thread(someRunnable)...is started when the 1st remote call comes in...??)



- according to the books, we should not crate threads within EJB's... so ??



- What is the scope of 'EJB' - if it has some dependencies that is outside the EJB module (e.g: in IBM WSAD5), do we consider the dependencies a part of EJB? So should we impose the limitations defined by the specs for the dependencies?



- We are not supposed to use "synchronized" in EJB's but I do see some sample from Sun's website that uses Vector for stateful session bean? Does this mean dependencies are not part of EJBs?



- If I'm required by architect to use a big Hastable to hold data (instead of a database) that is shared by all the clients, at the same time, what types of EJB should we use?Currently it is a static variable in a stateless session bean in the old project. But there is no special handling for this static table, the code does use 'synchronized' key word as if this code were written for a regular Java project. Is this OK? If not, what should I do for this?



If you know the answers please respond asap and I'll appreciate your help very much!!



Thanks,

Yulin.

   <<Less

Re: A few questions about EJB: scope, synchronized ...

Posted By:   Nick_Maiorano  
Posted On:   Wednesday, August 20, 2003 06:35 PM

Yulin,



The thing about these rules is that they are not enforced by the EJB container. You can break these rules as long as you know what you are doing.



Threads: The reason you shouldn't create threads is because EJBs abstract this for you. EJBs handle concurrency so why would you want to create threads? There is rarely a good reason to do so in an EJB application. Also, app servers have thread pools that allow you to configure and tune your application for performance. So using threads on top of this framework would defeat the purpose of an app server. But if you have a good reason for managing your own thread, it will still work.



Synchronized: There are cases where you need to synchronize methods inside an EJB-based app. For example, you are sharing a vector across all classes inside the ejb container. Here again, you need to know the consequences of this. EJB containers may use multiple classloaders for an application. The synchronize method will not synchronize a method for a same object that exists within 2 classloaders. This is also a problem for a clustered deployment.



As far as using a big hashtable, your current solution is fine. Just note the points I made in the previous paragraph.

About | Sitemap | Contact