Hi, You are 100% right. As per the EJB spec 'synchronized' shd not be used,and the reason is very simple,as you must be knowing that 'synchronized' keyword is used to avoid sharing conflict of a common resource in multi-threaded env. And J2EE application are multithread,so its container responsibilities to handle all these stuff for user. Even if you use 'synchronized' keyowrd in J2EE application than you are trying to make your container life tuff which you shd not be the case. Conatiner will do better handling of common resource,so we shd not use 'synchronized' keyword. hope that this will help you.
Cheers, Sunil Dixit [ July 05, 2007: Message edited by: Sunil Dixit ]
Joined: Aug 26, 2003
Thank you Sunil for your answer.
I totally agree with you but I found the following answer in this forum:
The EJB spec forbids you to make EJB methods synchronized, but it's generally OK to call a synchronized method in a helper class... Kyle
(Helper Class This could apply to my case (use of a helper class).
So this question still remains: Where is it stated in the specifications, that the "synchronized" keyword is forbidden?
Thank you for your help.
Joined: Sep 22, 2005
Hi, I don't agree with Kyle quotes,if that is true than we can do I/O in EJB using some helper class right ?
THIN line is EJB spec are the guidelines which say you should do that BUT it does not enforce user that he has to do that.
It 100% true that "synchronized" keyword is forbidden and the reason I have explained you.
I don't agree with Kyle quotes,if that is true than we can do I/O in EJB using some helper class right ?
Yes, under certain circumstances. Don't get confused between can and should. For example, a helper class called from a session bean that preforms IO should be OK, presuming you can tolerate the non-transactional nature of file system IO, you don't deploy your EJB in a distributed environment, and you don't do any OS specific IO. You will also be undermining your security model, and changes to admin privileges on the host OS will have to be handled carefully, but this may be acceptable. For the reasons above it's not a smart thing to do, following the specification means you will stear clear of any such issues. [ July 09, 2007: Message edited by: Paul Sturrock ]