Iplanet kjs servlet init() method

In iplanet is the servlet init method called in each KJS engine.
I have a continous thread running in a servet.This is invoked by a webased hyperlink.Some times ther happens to be 2 threads running and results in false operations.Conflict b/w threads.
Suspect one thread in each KJS is running.

This is the incorrect forum for this question. Sun ONE Application Server 7 is a completely new appserver and does not have KJS related technologies or APIs. Please check AppServer 6 forum.
HTH.
Paul

Similar Messages

  • Servlet init() method called multiple times

    We have a Servlet-based application which does lengthy initialization.
    We've noticed that when multiple requests arrive,
    but the Servlet's init() method has not returned yet
    for the first request, the application server calls init() multiple times.
    You can even see this with the Fortune sample
    Servlet. Starting the app server and sending 20 or 30
    simultaneous requests causes multiple Fortune Servlet init messages to appear in the kjs log.
    Why is this? We do not implement SingleThreadModel.
    Doesn't the J2EE 1.2 spec say init will be called
    only once?
    How do we prevent it?
    A Startup class which inits our
    Servlet?
    Or a synchronized block within our init method, with some checks of static member variables
    so that the initialization work only happens once?
    Or is there some kregedit magic or deployment descriptor change I could make?
    Again, it's not a SingleThreadModel issue, so don't
    point me there.
    This is iAS 6.0 SP4, on Solaris, by the way.

    Hi
    Yes,you are right. In iAS6.0 SP4 When multiple requests arrive,and the Servlet's init() method has not returned yet for the first request, the application server calls init()multiple times. This problem is resolved in iAS 6.5.
    There is no kregedit magic that will solve this problem.
    Right now the workaround is any of the solution you proposed. Or use iAS6.5. I have tested it with fortune.
    Please download it and check with your application.
    you can find free download at http://developer.iplanet.com/appserver/testdrive/testdrive_65.html
    Thanks

  • Why does SunOne 6.1 call servlet init() method twice on startup

    Hi,
    SunOne6.1 sp 5 is running my servlet's init() method twice when I put load-on-startup in the web-xml file. Is this a known problem and is there a work around as no amount of synchronising seems to work.
    I'm running 2.3.dtd for the default_web.xml file and my entries look like this :-
    <servlet>
    <servlet-name>RelatisLogin</servlet-name>
    <servlet-class>com.MyServlet</servlet-class>
    <load-on-startup>7</load-on-startup>
    </servlet>
    This init method only contains a basic check at the moment :-
    public void init()
    System.out.println("init.....");
    If I take <load-on-startup> away and run the server then call the servlet via the url it only runs init once.
    I've tried synchronizing the block but this doesn't work.
    The synchonization code I used looks like this:-
    public void init(ServletConfig config) throws ServletException
    synchronized( AnotherClass.staticString )
    if ( AnotherClass.staticString.length() > 0 ) return;
    System.out.println( AnotherClass.staticString.length() );
    AnotherClass.staticString = "init has been called";
    try
    int i = 0;
    i = i/i;
    } catch(Exception e)
    e.printStackTrace();
    The declaration of "AnotherClass.staticString" is :-
    public static String staticString = "";
    The output of "System.out.println( AnotherClass.staticString.length() );" is 0 and displayed twice.
    I deliberately cause a divide by zero error to get a stack trace so that i can determine what called init(), the stack trace is printed twice and is always :-
    java.lang.ArithmeticException: / by zero
    at com.MyServlet.init(MyServlet.java:47)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:921)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:813)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3478)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3760)
    at com.iplanet.ias.web.WebModule.start(WebModule.java:251)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:652)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:355)
    at org.apache.catalina.startup.Embedded.start(Embedded.java:995)
    at com.iplanet.ias.web.WebContainer.start(WebContainer.java:431)
    at com.iplanet.ias.web.WebContainer.startInstance(WebContainer.java:500)
    at com.iplanet.ias.server.J2EERunner.confPostInit(J2EERunner.java:161)
    It looks like SunOne starts then calls init() and then restarts and calls init() again.
    The same code and same web.xml entries work fine in Tomcat 5, init() only every gets called once.
    Any ideas? Can I post this as a bug?
    Thanks in advance for any help.
    Chris.

    Sorry to have not replied to this thread earlier.....forgot all about it.
    The reason init was being called twice by IPanet (Sun One) is IPanet comes with a default context called "Search" already in server.xml file.
    This context was loading all the classes on my class path and this causing "init" to run. Then my context entry also loaded all the files in the class path.
    Quite why Sun include this "Search" context is beyond me......annoying. If you take it out the the problem goes away.
    Basically if you leave this in then your running to web servers (JVM's) your one and Sun's stupid "Search" one. As they are separate JVM's no amount of synchronisation would ever fix it.

  • Invoking servlets init method

    Let's just say I want to write a startup class that initilizes a servlet,
              (just like ServletStartup class). How would I do this without using the
              URLConnection class?
              Thanks
              

    c00ler wrote:
    Hey guys,
    Studying JDBC & Java by O'Reilly. Old book, very old. You'd be better off with the Sun JDBC tutorial. Google for it.
    init() method is not really explained in the book and i'm kind of stuck. As far as i understand it's used to initialise servlet before its execution right? O'Reilly uses it to connect to the database (i'm find with connection part), problem is i don't understand why i can't connect through proccessRequest() method and I can't actually find the init() method within servlet...unless of course i write my own one. There is code offered by O'Reilly:
    Terrible form. More evidence of just how out of date this book is. No one would write a servlet to do this now.
    Book was published quite a few years ago...is there different implementation to this?
    Also for some reason Class.forName().newInstance() throws unidentified error if i use SQLException (even though java.sql.* is there), but works fine with Exception...any ideas???Not unidentified if you look at the javadocs for Class - it throws ClassNotFoundException, among others.
    You don't have to call newInstance() - Class.forName() is sufficient for registering the driver class.
    %

  • Need clarification - Rreg Servlets init method and construction

    Hi,
    My friends asks me 'Is init method of servlet is necessary? Can't we do whatever we want to do in Init method, in the constructor of the servlet? Why is init method is necessary?'
    Thanks in advance,
    Guhan

    byte[] tripleDesKeyData = key.getBytes();
    Instead of getting Bytes directly from that Hex string now i am getting in the following way......
    byte[] tripleDesKeyData = Encryption.tempHexStringToByteArray(key);
    public static byte[] tempHexStringToByteArray(String hexString){
         byte[] bytes = new byte[hexString.length() / 2];
         for (int i = 0; i < bytes.length; i++) {
              bytes[i] = (byte) Integer.parseInt(hexString.substring(2*i, 2*i+2), 16);
         return bytes;
    And using that key to decrypt....as of now its working fine now
    Why i am posting this is for others to use further....

  • OEM doesn't detect Servlet .init() failure!?!

    I'm trying to move some one-time initialization into a servlet .init() method and I wanted to see what would happen in OEM (Oracle Enterprise Manager) when this servlet's init() method failed (by throwing ServletException). I was hoping to see a Stop Sign or something...but instead OEM thinks everything is fine. Does anyone know how to make OEM aware of the actual state of the Servlets deployed under the OC4J containers it maintains?
    Bob
    package demos;
    import org.apache.struts.action.ActionServlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletContext;
    public class MyActionServlet extends ActionServlet {
    public MyActionServlet() { }
    public void init() throws ServletException {
    super.init();
    ServletContext sc = this.getServletContext();
    sc.setAttribute("AppScopeAttribute",
    "sc.toString()=" + sc.toString());
    sc.setAttribute("MyInitParam",
    this.getInitParameter("MyInitParam"));
    throw new ServletException(
    new Exception("This sucks...that sucks...everything sucks")
    }

    Maybe if I format the source better someone will render an opinion? I'm looking for ways to have the Oracle Enterprise Manager detect and report on .init() problems in my servlets. Here is a sample servlet that does nothing but throw and exception at .init() time. How can I configure OEM to react to and report this condition?
    package demos;
    import org.apache.struts.action.ActionServlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletContext;
    public class MyActionServlet extends ActionServlet {
      public MyActionServlet() { }
      public void init() throws ServletException {
        super.init();
        ServletContext sc = this.getServletContext();
        sc.setAttribute("AppScopeAttribute", "sc.toString()=" + sc.toString());
        sc.setAttribute("MyInitParam", this.getInitParameter("MyInitParam"));
        throw new ServletException( new Exception("This sucks...that sucks...everything sucks"));
    }

  • Configuring OEM to detect servlet.init() failures

    I'm trying to move some one-time initialization into a servlet .init() method and I wanted to see what would happen in OEM (Oracle Enterprise Manager) when this servlet's init() method failed (by throwing ServletException). I wrote a simple Servlet that does nothing but fail when it attempts to initialize. I was hoping to see a Stop Sign or something in OEM when I deloyed it, but instead OEM thinks everything is fine. Does anyone know how to make OEM aware of the actual state of the Servlets deployed under the OC4J containers?
    Bob
    package demos;
    import org.apache.struts.action.ActionServlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletContext;
    public class MyActionServlet extends ActionServlet {
    public MyActionServlet() { }
    public void init() throws ServletException {
    super.init();
    throw new ServletException( new Exception("I failed to init...DO SOMETHING!"));

    Maybe if I format the source better someone will render an opinion? I'm looking for ways to have the Oracle Enterprise Manager detect and report on .init() problems in my servlets. Here is a sample servlet that does nothing but throw and exception at .init() time. How can I configure OEM to react to and report this condition?
    package demos;
    import org.apache.struts.action.ActionServlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletContext;
    public class MyActionServlet extends ActionServlet {
      public MyActionServlet() { }
      public void init() throws ServletException {
        super.init();
        ServletContext sc = this.getServletContext();
        sc.setAttribute("AppScopeAttribute", "sc.toString()=" + sc.toString());
        sc.setAttribute("MyInitParam", this.getInitParameter("MyInitParam"));
        throw new ServletException( new Exception("This sucks...that sucks...everything sucks"));
    }

  • Urgent....How can i redirect to my jsp page from servlet in init() method..

    How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
    using RequestDispatcher..its not possible..becoz
    RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
    rd.foward(req,res);
    Here the request and response are null objects..
    So mi question can frame as how can i get request/response in servlet's init method()..

    Hi guys
    did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
    java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:519)
    at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
    at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
    at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
    so plz do let me know how to call a jsp in the start up of a servlet.
    Thanks
    Vidya

  • LDAP Context Initialization Problem in a Servlet's Init method

    Hi
    I have a servlet where I am using the InitialDirContext to Initialize context to a LDAP Server. I have created the context as a static variable. I am initializing the context in the init method and am using the same reference in the service method of the servlet. But if the context fails (due to naming exception and time out) in the init method all my requests in the service method will fail. Is there any way to validate the reference before using the same in the service method.
    Also what is the best approach to initialize the context in a servlet. Whether to initialize in the service method or the init method.
    I would appreciate if anyone can answer the above 2 queries.
    Thanks in advace,
    Ashish

    If you want to use threadsafe objects in doPost/doGet there are two common ways to do this.
    First, create the object in doPost/doGet. This may get expensive depending on the object, but it is 'easy' code and works.
    The second option is to create a pool of objects in the servlet's init() method and to just have doPost/doGet get an object from the pool, use it and return it when done. This take a little more work to code, but the overhead of creating objects is almost eliminated. Look at jakarta/apache commons pool for a quick way to do this.
    If you create on object in init() and use it in doPost/doGet, any time you get two request for the same servlet at the same time you will have synchronization issues that will usually cause problems. There is one instance of each Servlet, so all request for that servlet go through the single instance. Anything in doPost/doGet must be threadsafe.

  • Why Do We Have To Call super.init(config); in init() method of servlet?

    Hi, everyone..
    I wonder why we call super.init(config) in init method of servlet... If i dont call it ; when i try to get servletcontext in service method it throws java.lang.NullPointerException...when we call super.init() , what is happening behind the scene? If anybody has a technical explanation for my question , i will be very pleased...
    THX FOR YOUR FUTURE REPLIES IN ADVANCE....

    I am sorry about the uppercases and i dont want to seem smart on java forums... Anyway, m8 this is the thing that i know... i meant; for instance when we override doGet or doPost method ; we dont need to override init method; but the server loads the servlet and we can get the context of the servlet in these methods easily by calling getServletContext() method; however when we want to call service method implicitly by jndi, servlet needs to be loaded and init method must call its parent...(i also write down in web.xml <load-on-startup>.... for that servlet).
    thx for your replies in advance....

  • Why do we use init() method instead of constructor to initialize a servlet?

    Why do we use init() method instead of constructor to initialize a servlet?

    I suspect the reasons are partly historical. A servlet is loaded dynamically, by class name and, once you've loaded the Class, it's easier to to a newInstance, using the default construtor than it is to search for a particular matching constructor and invoke it.

  • The servlet weblogic.servlet.AsyncInitServlet init method failed

    I installed WLS 9.2.2 recently with my app being on 8.1.5 for a long time.
    I chose to create a new domain instead of upgrading my existing one.
    I use the eclipse 3.2.2 with the WL plugin.
    When I start the server and login to the console not using eclipse it works fine.
    Trying to start the server and login to the console gives a internal server error.
    Any idea what could be wrong? I bolded the parts where I have looked into.
    Here is the console output:
    <Nov 19, 2008 3:13:02 PM CST> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
    C:\bea92\weblogic92\platform\lib\p13n\p13n-schemas.jar;C:\bea92\weblogic92\platform\lib\p13n\p13n_common.jar;*C:\bea92\weblogic92\platform\lib\p13n\p13n_system.jar*;C:\bea92\weblogic92\platform\lib\wlp\netuix_common.jar;C:\bea92\weblogic92\platform\lib\wlp\netuix_schemas.jar;C:\bea92\weblogic92\platform\lib\wlp\netuix_system.jar;C:\bea92\weblogic92\platform\lib\wlp\wsrp-common.jar>
    <Nov 19, 2008 3:13:03 PM CST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with Java HotSpot(TM) Client VM Version 1.5.0_10-b03 from Sun Microsystems Inc.>
    <Nov 19, 2008 3:13:05 PM CST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 9.2 MP2 Mon Jun 25 01:32:01 EDT 2007 952826 >
    <Nov 19, 2008 3:13:10 PM CST> <Info> <WebLogicServer> <BEA-000215> <Loaded License : C:\bea92\license.bea>
    <Nov 19, 2008 3:13:10 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING>
    <Nov 19, 2008 3:13:10 PM CST> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool>
    <Nov 19, 2008 3:13:11 PM CST> <Notice> <Log Management> <BEA-170019> <The server log file C:\bea92\user_projects\domains\domain\servers\AdminServer\logs\AdminServer.log is opened. All server side log events will be written to this file.>
    <Nov 19, 2008 3:13:15 PM CST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.>
    <Nov 19, 2008 3:13:22 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY>
    <Nov 19, 2008 3:13:22 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING>
    <Nov 19, 2008 3:13:30 PM CST> <Error> <HTTP> <BEA-101359> <The servlet weblogic.servlet.AsyncInitServlet init method failed while it was run in the background. The exception was: java.lang.NoClassDefFoundError: com/bea/p13n/management/ApplicationFilePoller$Handler.
    java.lang.NoClassDefFoundError: com/bea/p13n/management/ApplicationFilePoller$Handler
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
         Truncated. see log file for complete stacktrace
    >
    <Nov 19, 2008 3:13:37 PM CST> <Notice> <Log Management> <BEA-170027> <The server initialized the domain log broadcaster successfully. Log messages will now be broadcasted to the domain log.>
    <Nov 19, 2008 3:13:37 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN>
    <Nov 19, 2008 3:13:37 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING>
    <Nov 19, 2008 3:13:39 PM CST> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 127.0.0.1:7005 for protocols iiop, t3, ldap, http.>
    <Nov 19, 2008 3:13:39 PM CST> <Notice> <WebLogicServer> <BEA-000331> <Started WebLogic Admin Server "AdminServer" for domain "domain" running in Development Mode>
    <Nov 19, 2008 3:13:40 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING>
    <Nov 19, 2008 3:13:40 PM CST> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode>
    <Nov 19, 2008 3:22:04 PM CST> <Error> <HTTP> <BEA-101020> <[weblogic.servlet.internal.WebAppServletContext@d6c6a0 - appName: 'consoleapp', name: 'console', context-path: '/console'] Servlet failed with Exception
    java.lang.NullPointerException
         at weblogic.servlet.AsyncInitServlet.service(AsyncInitServlet.java:124)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         Truncated. see log file for complete stacktrace
    Edited by: user5384782 on Nov 19, 2008 1:42 PM
    Edited by: user5384782 on Nov 19, 2008 3:59 PM

    Thanks for your replies adrian and david.
    The only thing I see different is that eclipse has different arguments when calling the jvm at the top.
    startWebLogic.cmd:
    C:\bea92\JDK150~1\bin\java -client -Xms256m -Xmx512m -XX:CompileThreshold=8000
    -XX:PermSize=48m -XX:MaxPermSize=128m -Xverify:none -da -Dplatform.home=C:\b
    ea92\WEBLOG~1 -Dwls.home=C:\bea92\WEBLOG~1\server -Dwli.home=C:\bea92\WEBLOG~1\i
    ntegration -Dweblogic.management.discover=true -Dwlw.iterativeDev= -Dwlw.testC
    onsole= -Dwlw.logErrorsToConsole= -Dweblogic.ext.dirs=C:\bea92\patch_weblogic922
    \profiles\default\sysext_manifest_classpath -Dweblogic.Name=AdminServer -Djava.s
    ecurity.policy=C:\bea92\WEBLOG~1\server\lib\weblogic.policy weblogic.Server
    eclipse:
    -hotspot -Xms32m -Xmx200m -Dweblogic.ProductionModeEnabled=
    Eclipse may be calling the cmd I dont know.
    I will try upgrading my eclipse like adrian said, but in the meantime I appreciate any further advice/tips.

  • How servlet's init method is overridden ?

    Here is a sample code to override servlet's init method.
    public class BookDBServlet ... {
            private BookstoreDB books;
            public void init(ServletConfig config) throws ServletException {
                // Store the ServletConfig object and log the initialization
                super.init(config);
                // Load the database to prepare for requests
                books = new BookstoreDB();
        }I dont get why super.init(config); is called.
    Comment says +// Store the ServletConfig object and log the initialization+
    what does "Store" mean here ? Where it is stored ?
    how it is logged ( log4j / commons -logging ? ) and where (which file) it is logged ?
    Can we remove this line without any damage ?

    There are several calls you can make to the servlet object which are simply delegated to the ServletConfig object, most notably getServletContext(). The default action of the init(SerletConfig config) method is to store the config in a field which is defined in GenericServlet, so that these calls can work. If you don't do this then calling getServletContext() at some later time will give you a NullPointerException.
    I think the reference to logging is that, if you use the built in servlet logging system, rather than log4j or java.util.loging then this depends on a valid servlet context, which in turn, depends on a valid servlet config reference.

  • Monitoring progress of init() method in servlet

    the init() method of my servlet is extremely long; it will probably take several minutes to load. For this reason, I want to have my servlet print its progress periodically. Unfortunately, when initializing a servlet, Tomcat does not allow the System.out.println() method to do anything.
    Is there a way to tell tomcat to print something to the screen while it is initializing the servlets?

    You can write jamon monitors after each event that occurs in the init method. Then if you go to the jamonadmin page you can see the progress. You will find many other uses for jamon too. One thng that it does real well is to allow you to look at what is currently executing in your web application via the jamonadmin page.
    It is easy to use. Really just 2 methods: start and stop. see below. You should be able to get it working in minutes.
    jamon is an open source project. Also if you use the servlet filter it will keep stats such as hits, and time stats (avg, total, min, max) and more.
    import com.jamonapi.*;
    // i'm not sure of the actual signature name, but this should give you the point.
    public void init() {
    Monitor mon=MonitorFactory.start("executing Part1 Of Init")
    ... part 1...
    mon.stop();
    Monitor mon=MonitorFactory.start("executing Part2 Of Init")
    ... part 2...
    mon.stop();To get jamon go to www.jamonapi.com. There is also a live program that lets you see the JAMonAdmin.jsp page in action.
    steve - http://www.jamonapi.com

  • Why Servlet has init method?

    Hello,
    i am new bie to servlet. Can you tell me why servlet has init method to initialize?
    Why do not we use constructor instead of init method to initialize? Does servlet allow constructor?
    Why init method has SevletConfig as argument?
    Please help me to get knowledge regarding this. Any URL for this(sun or anything), please send.
    Thanks,
    balachandar

    http://www.unix.org.ua/orelly/java-ent/servlet/ch03_03.htm

Maybe you are looking for