Discussions

EJB programming & troubleshooting: Ejb instance pooling

  1. Ejb instance pooling (1 messages)

    Server-WLS 6.1
    I want to create a single instance of a stateless session ejb, on server start up, to perform some scheduling functions.
    I tried using the "initial beans in pool" and the "max beans in pool" properties in the deployment descriptor initializing both these properties to one.
    But i find that more than a single instance is being created , to be precise "5".
    Is there any default setting in WLS, which places a restriction on the minimum number of beans that can be created in the pool.

    Threaded Messages (1)

  2. Ejb instance pooling[ Go to top ]

    Hi!

    In WLS 6.1 you can use the startup classes to do this. (If you look arount inte the admin UI you will find it. I don't have WLS 6.1 on my PC now, so I cannot give the exact details.) You have to define a startup class and assign to your application. In the startup code you can start you can use the java.util.Time class to start what you want and when you want to start it. With this approach, you don't need an EJB to do it.

    This is a startup class from my project library: (Executed on WLS 6.1_SP4. The example starts Log4j.)

    import weblogic.common.T3StartupDef;
    import weblogic.common.T3ServicesDef;

    import java.util.Hashtable;

    import org.apache.log4j.PropertyConfigurator;
    import org.apache.log4j.Logger;
    import org.apache.log4j.LogManager;

    /**
     * WebLogic Server startup class adding an appender to the Log4j package. The
     * startup property <ocde>file</code> contains the full path to the Log4j
     * configuration file (in the <code>Properties</code> format). Note that the
     * path is given without escape character (\) in the admin interface.
     * <br>
     * The use of startup classes are outside the J2EE specification.
     * <br>
     * The class is developed for and tested on WebLogic Sevrer 6.1 SP 4.
     */
    public class StartLog4jWLS61 implements T3StartupDef {

        public String startup(String name, Hashtable properties) {
            Object obj = properties.get("file");
            if (obj==null) {
                return "Parameter 'file' missing in configuration.";
            }

            String file = (String) obj;
            PropertyConfigurator.configure(file);
            Logger log = LogManager.getLogger(StartLog4jWLS61.class);
            log.info("Log4j init by StartLog4jWLS61 OK.");
            return "Log4j initiated properly from file '" + file + "'.";
        }

        public void setServices(T3ServicesDef def) {}
    }

    This is not standard EJB (or J2EE). I know other (standard) solutions to make things on startup in an EJB application, but they more complex and I don't want to explain them here. (If you write a Web application, there is a <load-on-startup> tag in web.xml to do what you want.)

    It is important to put you startup class in a JAR file outside the EJB application JAR file, and address this other JAR file in the CLASSPATH in the WLS start script (startWebLogic.cmd on Windows.)

    When it comes to the "start a timer" issue in the EJB container, this is not allowed according to the programming restrictions in the spec. (At least not as I interpret the spec.) However, to me this is not a problem as long as you really know what you are doing and can explain why it works anyway.)

    /Tomas