on 05-10-2007 12:24 PM
Hi,
I have a utility class which is shared by multiple EJBs. The issue is that, I want this util to be singleton and accessed by multiple EJBs. But I could see that each EJB is initializing its on utility class. How can I stop it.
Steps I have done to create this scenario:
create a normal java project and add this to each EJB project.
Any suggestions are welcome!
regards
Vivek Nidhi.
Hi Vivek,
You need a shared library for the singleton class to be initialized only once.
Have a look at <a href="/people/community.user/blog/2006/10/24/applications-and-shared-libraries">this</a> blog.
Hope it helps!
-Vladimir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just wanted to clarify that this is not a restriction by any means. If you follow the blog mentioned above, you can definitely have your EJBs in separate applications (EARs), hence better componentization.
Please also check the <a href="http://help.sap.com/saphelp_nwce10/helpdata/en/44/f4e00e56ec0486e10000000a155369/frameset.htm">Working with Libraries</a> document, especially Standard libraries.
-Vladimir
Hi Vladimir,
I checked the blog but it requires some latest service pack and it should be J2EE 1.5
currently either my clients or my NWDS are not supporting that version.
Also I have done the same thing in application Servers like IBM Websphere. Where in you can add the jar to the Application Server path and rest of the applications will share it. To my surprise I tried the same way add a application server lib DC to the server, it was pretty complex and didnt work.
So my question is what is that so different in SAP WAS, Is the classloading policies or its using a different approach for loading lib.
Hi Vivek,
Since your post was in the Java EE 5 @ SAP forum, I assumed you are using the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1011818d-1abe-2910-5897-f72eb59c951a">SAP NetWeaver Composition Environment Trial Version</a> or at least the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/da699d27-0b01-0010-99b0-f11458f31ef2">SAP NetWeaver Application Server, Java EE 5 Edition</a>. The blog is dealing with exactly these two releases.
> So my question is what is that so different in SAP WAS,
> Is the classloading policies or its using a different approach for loading lib.
Well, both. The blog explains that too. You cannot simply drop a jar into some "shared" folder and expect it to be visible to all deployed apps. That's what shared application libraries are designed and meant for.
Hope this makes the picture a bit more clear.
-Vladimir
I solved the issue myself by packing everything in an EAR.
The class was getting loaded only once. Thanks for all the help
Message was edited by:
Vivek Nidhi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
There may be some syntax error in the Jsp page.
eg: you may not have closed the html
and also check that whether u have given sharing reference for htmlb tag in portal.xml file
Regards,
Beevin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vivek,
As you said If you singleton, I think you can avoid EJB from creating no of instances.
For instance see here
public class Singleton {
private Singleton() {}
private static class SingletonHolder {
private static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.instance;
//<b>Here this make sure that everytime only one instance is returned to calling program.</b> }
}
I hope this is the standrad method I guess. You can use thread concept also for the same purpose but that makes code difficult to understand
Hope that helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.