cancel
Showing results for 
Search instead for 
Did you mean: 

class loading Issue in EJB

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Vlado
Advisor
Advisor
0 Kudos

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

Former Member
0 Kudos

Hi,

I solved this Issue by bundling all EJB in one EAR.

Any one has any document on Class Loading in Web AS. Please let me know the details.

regards

Vivek Nidhi

Former Member
0 Kudos

Hi Vivek,

<a href="http://help.sap.com/saphelp_nwce10/helpdata/en/1d/b11e3e3986f701e10000000a114084/frameset.htm">this</a> is what I found in documentation about class loading. Let me know if it helps.

Vlado
Advisor
Advisor
0 Kudos

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

Former Member
0 Kudos

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.

Vlado
Advisor
Advisor
0 Kudos

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

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

praveenkumar_kadi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

HI,

Actually I am asking about how to use a library in many EJBs. Not about coding a singleton pattern.