Why is the static initializer instantiating my class?!

It seems that the static { ... } blocks for my enhanced classes actually
create instances of those classes. Gack! It seems, furthermore, that
this is due to the JDO spec itself, whose JDOImplHelper.registerClass()
requires an instance of the class being registered. Double gack!
This is causing a problem for me, because I've put a sequence generator in
my class's constructor. Now merely **loading** a PC class will cause my
sequence to be incremented (not great), or will throw an exception if the
environment isn't set up for the sequence generator (terrible). This
latter problem happens if I enhance my classes, then try to enhance them
again -- the enhancer tries to load my class, the static { ... } block
tries to load the sequence generator, and the whole enhancer blows up.
Questions:
* Why is this necessary? Why does JDOImplHelper.registerClass() take an
instance of the class being registered? Could the call to
JDOImplHelper.registerClass() happen the first time the ctor is called,
instead of inside a static { ... } block?
* Given that the above questions probably have reasonable answers, how
should I work around this problem?
Thanks,
Paul

Hi Patrick,
Do you understand why jdoNewInstance and jdoNewObjectIdInstance are not static? And if that could
be done, would that void the need to register the class when loaded?
David
Patrick Linskey wrote:
>
On 5/28/02 12:39 PM, "Paul Cantrell" <[email protected]> wrote:
Questions:
* Why is this necessary? Why does JDOImplHelper.registerClass() take an
instance of the class being registered? Could the call to
JDOImplHelper.registerClass() happen the first time the ctor is called,
instead of inside a static { ... } block?The JDO spec inserts some utility methods into PersistenceCapable classes
for which it needs a method around.
These utility methods are the jdoNewInstance() methods and the
jdoNewObjectIdInstance() methods. These methods improve performance by
allowing PersistenceCapable objects and application ID OID classes to be
created without using reflection.
This class registration must occur at class initialization time, because
your first operation on the class might very well be to look up objects of
that class from the data store, in which the no-args constructor might not
be called.
* Given that the above questions probably have reasonable answers, how
should I work around this problem?Your best bet is probably to not do the sequence generation in your no-args
constructor. One option would be to create a constructor with a marker
boolean that designates if sequence generation should occur; another
probably more elegant solution would be to create a factory method that uses
the default constructor and then assigns an ID, or fetches an ID and then
invokes a non-default constructor with that ID.
-Patrick
Patrick Linskey [email protected]
SolarMetric Inc. http://www.solarmetric.com

Similar Messages

  • Problems with static member variables WAS: Why is the static initializer instantiating my class?!

    Hi,
    I have been hunting down a NullPointerException for half a day to come to
    the following conclusion.
    My constructor calls a method which uses static variables. Since an intance
    of my class is created in the static block when the class is loaded, those
    statics are probably not fully initialized yet and the constructor called
    from the static block has those null pointer problems.
    I've considered moving the initialization of the static variables from the
    declaration to the static block. But your code is inserted BEFORE any other
    code. Therefore not solving my problem.
    Two questions:
    1) what would be a solution to my problem? How can I make sure my static
    variables are initialized before the enhancer generated code in the static
    block calls my constructor? Short of decompiling, changing the code and
    recompiling.
    2) Why is the enhancing code inserted at the beginning of the static block
    and not at the end? The enhancements would be more transparent that way if
    the static variables are initialized in the static block.
    Thanks,
    Eric

    Hi Eric,
    JDO calls the no-args constructor. Your application should regard this constructor as belonging
    primarily to JDO. For example, you would not want to initialize persistent fields to nondefault
    values since that effort is wasted by JDO's later initilization to persistent values. Typically all
    you want to initialize in the no-args constructor are the transactional and unmanaged fields. This
    rule means that you need initialization after construction if your application uses the no-args
    constructor and wants persistent fields initialized. On the other hand, if your application really
    uses constructors with arguments, and you're initializing persistent fields in the no-args
    constructor either unintentionally through field initializers or intentionally as a matter of
    consistency, you will find treating the no-args constructor differently helpful.
    On the other hand, if Kodo puts its static initializer code first as you report, then it is a bug.
    Spec Section 20.16: "The generated static initialization code is placed after any user-defined
    static initialization code."
    David Ezzio
    Eric Borremans wrote:
    >
    Hi,
    I have been hunting down a NullPointerException for half a day to come to
    the following conclusion.
    My constructor calls a method which uses static variables. Since an intance
    of my class is created in the static block when the class is loaded, those
    statics are probably not fully initialized yet and the constructor called
    from the static block has those null pointer problems.
    I've considered moving the initialization of the static variables from the
    declaration to the static block. But your code is inserted BEFORE any other
    code. Therefore not solving my problem.
    Two questions:
    1) what would be a solution to my problem? How can I make sure my static
    variables are initialized before the enhancer generated code in the static
    block calls my constructor? Short of decompiling, changing the code and
    recompiling.
    2) Why is the enhancing code inserted at the beginning of the static block
    and not at the end? The enhancements would be more transparent that way if
    the static variables are initialized in the static block.
    Thanks,
    Eric

  • How to reference a static variable before the static initializer runs

    I'm anything but new to Java. Nevertheless, one discovers something new ever' once n a while. (At least I think so; correct me if I'm wrong in this.)
    I've long thought it impossible to reference a static variable on a class without the class' static initializer running first. But I seem to have discovered a way:
    public class Foo  {
      public static final SumClass fooVar;  // by default initialized to null
      static  {
         fooVar = new SumClass();
    public class Bar  {
      public static final SumClass barVar;
      static  {
         barVar = Foo.fooVar;  // <<<--- set to null !
    }Warning: Speculation ahead.
    Normally the initial reference to Foo would cause Foo's class object to instantiate, initializing Foo's static variables, then running static{}. But apparently a static initializer cannot be triggered from within another static initializer. Can anyone confirm?
    How to fix/avoid: Obviously, one could avoid use of the static initializer. The illustration doesn't call for it.
    public class Foo  {
      public static final SumClass fooVar = new SumClass();  // either this ..
    public class Bar  {
      public static final SumClass barVar = Foo.fooVar;  // .. or this would prevent the problem
    }But there are times when you need to use it.
    So what's an elegant way to avoid the problem?

    DMF. wrote:
    jschell wrote:
    But there are times when you need to use it. I seriously doubt that.
    I would suppose that if one did "need" to use it it would only be once in ones entire professional career.Try an initializer that requires several statements. Josh Bloch illustrates one in an early chapter of Effective Java, IIRC.
    Another classic usage is for Singletons. You can make one look like a Monostate and avoid the annoying instance() invocation. Sure, it's not the only way, but it's a good one.
    What? You only encounter those once in a career? We must have very different careers. ;)
    So what's an elegant way to avoid the problem? Redesign. Not because it is elegant but rather to correct the error in the design.<pff> You have no idea what my design looks like; I just drew you a couple of stick figures.If it's dependent on such things as when a static initializer runs, it's poor. That's avoidable. Mentioning a case where such a dependency is used, that's irrelevant. It can be avoided. I know this is the point where you come up with a series of unfortunate coincidences that somehow dictate that you must use such a thing, but the very fact that you're pondering the problem with the design is a design problem. By definition.
    Besides, since what I was supposing to be a problem wasn't a problem, your "solution" isn't a solution. Is it?Well, you did ask the exact question "So what's an elegant way to avoid the problem?". If you didn't want it answered, you should have said so. I'm wondering if there could be any answer to that question that wouldn't cause you to respond in such a snippy manner. Your design is supposedly problematic, as evidenced by your question. I fail to see why the answer "re-design" is unacceptable. Maybe "change the way the Java runtime initializes classes" would have been better?
    This thread is bizarre. Why ask a question to which the only sane answer, you have already ruled out?

  • Why is the static method in the superclass more specific?

    Why is the static method in the superclass more specific than the static method in the subclass? After all, int is a subtype of long, but Base is not a subtype of Sub.
    class Base {
        static void m(int i){ System.out.println("Base"); }
    class Sub extends Base {
        static void m(long l){ System.out.println("Sub"); }
    class Test {
        public static void main(String[] args) {
            int i = 10;
            Sub sub = new Sub();
            sub.m(i);
    }The first example compiles without error.
    Output: Base
    class Base {
        void m(int i){ System.out.println("Base"); }
    class Sub extends Base {
        void m(long l){ System.out.println("Sub"); }
    class Test {
        public static void main(String[] args) {
            int i = 10;
            Sub sub = new Sub();
            sub.m(i);
    }In the second example, both instance methods are applicable and accessible (JLS 15.12.2.1), but neither is more specific (JLS 12.2.2), so we get a compiler error as expected.
    : reference to m is ambiguous,
    both method m(int) in Base and method m(long) in Sub match
    sub.m(i);
    ^
    1 error
    Why don�t we get a compiler error for the static methods?

    Thank you for your ideas.
    ====
    OUNOS:
    I don't get Sylvia's response. This is about static methods, what are instances are needed for??Yes, the question is about static methods. I included the example with non-static methods for a comparison. According to JLS 15.12.2, both examples should cause a compiler error.
    And why you create a Sub object to call the method, and dont just call "Sub.m(..)"Yes, it would make more sense to call Sub.m(i). Let�s change it. Now, I ask the same question. Why is there no compiler error?
    ====
    DANPERKINS:
    The error in your logic stems from calling static methods on instances, as ounos pointed out. Solution: don't. You won't see any more ambiguities.A static member of a class may also be accessed via a reference to an object of that class. It is not an error. (The value of the reference can even be null.)
    Originally I was looking only at the case with non-static methods. Therefore, I used sub.m(i). Once I understood that case, I added the static modifiers. When posting my question, I wish I had also changed sub.m to Sub.m. Either way, according to JLS 15.12.2, a compiler error should occur due to ambiguous method invocation.
    ====
    SILVIAE:
    The question was not about finding an alternative approach that doesn't throw up an ambiguity. The question related to why, in the particular situations described, the ambiguity arises in only one of them.
    Yes.
    Proposing an alternative approach doesn't address the question.
    Yes.
    ====
    If anyone is really interested, here is some background to the question. Some people studying for a Sun Java certificate were investigating some subtleties of method invocations:
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=019182
    I remember seeing the non-static case discussed in this forum once before in a more practical context. jschell probably knows the link.

  • Is static initialization of a class varaible guaranteed to occur only once?

    In other words, if two threads attempt to create an instance of this class, would the static initialization of ConnectionFactory occur once?
    public ConnectionSource {
    private static ConnectionFactory factory = new ConnectionFactory();
    I need exactly one instance of ConnectionFactory.
    SAF

    if ConnectionSource is unloaded (because there are no references to any instances on ConnectionSource, and no reference to the Class object itself), then a different ConnectionFactory would be created when the class is reloaded. This may or may not affect your program execution.
    Hackmann

  • Why are the Java Library source code classes not indented properly?

    I have always admired the design of a lot of classes and frameworks in the JDK. I read the source code a lot to see how the developers coded a particular class, how they designed it and how they write the javadocs.
    But one thing I observed was the improper indentation of the source code. Why is this so?

    I have always admired the design of a lot of classes
    and frameworks in the JDK. I read the source code a
    lot to see how the developers coded a particular
    class, how they designed it and how they write the
    javadocs.
    But one thing I observed was the improper indentation
    of the source code. Why is this so?Repeating what was said above....do not look upon the Java API as an example of how to do anything, not for design, not for code implementations and not even for code structure.

  • Static Initializer in PK Class

    What's the purpose of this line:
    static{
    Class c = StringPK.class;
    in pk classes generated by kodo's pk tool?
    Dave Ford
    Smart Soft - The Developer Training Company
    http://www.smart-soft.com

    This allows us a chance to force class loading. Each PersistenceCapable
    class registers with the core JDO classes, which in turn allows us to
    probe the registered class for base information stored during the
    enhancement process.
    Otherwise, it is possible that we would have no idea of what class the
    object-id resolves to without searching your entire classpath for
    ..metadata files, as the spec calls for no specific method to return the
    matching PersistenceCapable class for a given object-id.
    Dave Ford wrote:
    What's the purpose of this line:
    static{
    Class c = StringPK.class;
    in pk classes generated by kodo's pk tool?
    Dave Ford
    Smart Soft - The Developer Training Company
    http://www.smart-soft.com
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • Why have the file name MyClass$1.class

    Hi all,
    Please exlain why have class file with $1, $2 (example: MyClass$1.class)
    If i delete it, do my program run ?
    thanks

    Hi all,
    Please exlain why have class file with $1, $2
    (example: MyClass$1.class)
    Those are anonymous inner classes you created in your MyClass code.
    If i delete it, do my program run ?Not well anyway.

  • Static initializer not invoked

    Why is the static initializer of B (in the example below) is not invoked?
    public class A {
         public static void m1() {
              System.out.println("static m1 in A");
    public class B extends A{
         static {
              System.out.println("static init B");
         public static void m2() {
              System.out.println("static m2 in A");
    public class Main {
         public static void main(String[] args) {
              B.m1();
    Surprisingly the console output is just 'static m1 in A'.

    Class B doesn't have a static method named m1(). But its superclass does, so it's that method that is called. (Static methods are not inherited.) To call a method of class A, it's only necessary to load class A.

  • Why is it necessary to create an instance via the static method?

    Hi,
    For some classes (such as java.util.regex.Pattern), we should call the class method (static method) in order to create an instance (object).
    For example, in order to conduct the pattern matching, we should use the java.util.regex.Pattern class as follows:
    Pattern p = Pattern.compile ("X[0-9]+X") ;
      // An instance of the Pattern class is created.
    Matcher m = p.matcher ("abcX1XYX23Xz") ;
    while ( m.find() ){
      System.out.println ( m.start() ) ;
    }where the compile static method in the Pattern class creates an instance and returns the pointer (reference) of it. We should NOT call
    the constructor of the Pattern class as follows:
    Pattern p = new Pattern ("X[0-9]+X") ;    // ERRORThe question is the following:
    (1) In what scenes, do we develop the classes that force users to call the static method for creating an instance of it?
    (2) Why do the java.util.regex.Pattern class have such a specification?
    Thanks in advance.

    (1) In what scenes, do we develop the classes that force users to call the static method for creating an instance of it?1. As the other author mentioned, caching is one reason.
    2. With such caching, you don't need to take trouble in passing the reference of a cached object(s) to many places in your code. From anywhere in your code base, you can simply invoke the method, the object will come. In essence, the static method provides a global point of access to one or more pre-created (or cached) objects. Hence, the static method simplifies access to the object.
    3. Sometimes, the actual class instantiated is not the same as the one with the static method. This allows abstraction of underlying variations. For example, when you say Pattern.compile ("X[0-9]+X") , the returned object type can be different in Windows and Linux (Most probably Pattern class doesn't work like that, but I am showing you a use case. May be Runtime.getRuntime() does actually work like that.). You find this abstraction of variations in many places. Take for example, FacesContext.getExternalContext() method (this is from JSF API). ExternalContext documentation says this:
    "This class allows the Faces API to be unaware of the nature of its containing application environment. In particular, this class allows JavaServer Faces based appications to run in either a Servlet or a Portlet environment."
    Edited by: Kamal Wickramanayake on Oct 24, 2012 8:04 AM

  • JNDI lookup in Static initializer

    Hi,
    Is there a problem looking up home interfaces in a static initializer in
    WL6.1?
    I have a class X which runs in my application client. It has a static
    initializer that looks up a home interface. The call to Context.lookup()
    times out with weblogic.rjvm.PeerGoneException: No message was received for:
    '240' seconds.
    The strange thing is, if I force the static initializer to run myself (by
    instantiating X directly), then it runs ok. I only get the above problem if
    the VM causes it to run (by loading a class Y that references X).
    Also, this behaviour is only apparent in the client. In the app server, X
    behaves correctly. I'm passing in JNDI properties as system properties on
    the command line to the client.
    Any help appreciated.
    Cheers,
    Manish

    Check the class loader and thread dump during the place where it works and
    the one where it doesn't ... that could help track down why it works that
    way.
    Peace,
    Cameron Purdy
    Tangosol Inc.
    << Tangosol Server: How Weblogic applications are customized >>
    << Download now from http://www.tangosol.com/download.jsp >>
    "Manish Shah" <[email protected]> wrote in message
    news:[email protected]..
    Hi,
    Is there a problem looking up home interfaces in a static initializer in
    WL6.1?
    I have a class X which runs in my application client. It has a static
    initializer that looks up a home interface. The call to Context.lookup()
    times out with weblogic.rjvm.PeerGoneException: No message was receivedfor:
    '240' seconds.
    The strange thing is, if I force the static initializer to run myself (by
    instantiating X directly), then it runs ok. I only get the above problemif
    the VM causes it to run (by loading a class Y that references X).
    Also, this behaviour is only apparent in the client. In the app server, X
    behaves correctly. I'm passing in JNDI properties as system properties on
    the command line to the client.
    Any help appreciated.
    Cheers,
    Manish

  • Help please with a Static Initializer for ImageIcons inside Jar Files

    At the moment I'm playing around displaying XML using A JTree
    I am subclassing DefaultMutableTreeNode, and want it to have some default Icons set up....
    Sort of like this:
    public class XNode extends DefaultMutableTreeNode
        public static final ImageIcon icon;
       public static ImageIcon getIcon()
            return XNode.icon;
    }The only thing is that for the life of me after trying various things and searching these forums and google:
    I can't work out how to write the static Initializer for the ImageIcon.
    The ImageIcon will need to be created using a URL, cos it will be inside my jar file.....
    the usual...
               URL url = this.getClass().getResource("/images/Exit16.gif");
               ImageIcon Icon = new ImageIcon( url );but I wanted these Icons to be class members..............
    Could someone help?
    }

    DrClap " I don't understand why you put Class.forName in there either"
    A: Because I don't really know what I'm doing.
    I will try that suggestion.
    At present I have this:
         static ImageIcon loadIcon;
         static
              try
                loadIcon = new ImageIcon( Class.forName("cis.editor.xml.nodes.AlNode").getResource("/images/Exit16.gif"));
              catch( ClassNotFoundException cnfe )
                   System.out.println("ClassNotFound: " + cnfe.getMessage() );
         public static final ImageIcon defaultIcon = loadIcon;
         static
              try
                loadIcon = new ImageIcon( Class.forName("cis.editor.xml.nodes.AlNode").getResource("/images/tree_folder_major.gif"));
              catch( ClassNotFoundException cnfe )
                   System.out.println("ClassNotFound: " + cnfe.getMessage() );
         public static final ImageIcon commentIcon = loadIcon;
    //.......... ANd so OnWhy? Because do far it was the only way I could get it to compile.
    And It works..
    However it's a real abortion.. codewise.
    I need to load about 16 Icons that the various subclasses can 'use'
    DefaultTreeCellRenderer - must do somethng similar because it has a bunch of Icons to "Pick from",
    Only How is that done 'properly' ?

  • Instance initializer and static initializer blocks

    Hi guys,
    I read about the above mentioned in the JLS and also in a book before, but I still don't quite understand, what is the use of these. I sort of have a rough idea, but not exactly. I mean, what is the purpose of the instance initializer and static initializer blocks, how can it be useful? I understand I can execute pieces of code that will initialize instance and static variables accordingly, but how is it different then to using a constructor to initialize these fields? Are these pieces of code executed before any constructor is executed, or when otherwise?
    Sorry for my noob, I'm learning.
    PR.

    Static initializers are useful for initializing a class when the initialization is more complex than simply setting a single variable, or when that initialization can throw a checked exception.
    public class Foo {
      private static final Bar bar;
      static {
        try {
          bar = new Bar();
          bar.doSomeInitializationStuff();
        catch (SomeCheckedExceptionThatBarThrows e) {
          throw new ExceptionInInitializerError(e);
    }Here we could not do the two-step new Bar() + doSomeInit() stuff in the line where we declare the bar variable. Additionally, assuming that one or both of those can throw a checked exception, we could not do that on the declaration line; we need the static initializer to wrap that in the appropriate unchecked exception.
    This allows us to do more complex class initialization when the class is loaded than we could do with a simple variable initialization.
    Instance initializers are useful if you want to perform the same steps in every constructor and don't want to have to repeat the code in each constructor. Instance initializers are executed as the first step of each constructor (or maybe it's after any super() calls, I forget).

  • How to force subclass static initialization?

    Interesting problem. Here's the setup:
    public class Properties1 implements Properties1Keys {
    private void Hashtable ht = new Hashtable();
    static { ht.put(prop1Key, "Test1"); }
    public static Object get(String key) { return ht.get(key); }
    public static void put(String key, Object o) { ht.put(key, o); }
    public interface Properties1Keys {
    public final static String prop1Key = "prop1";
    public class Properties2 extends Properties1 implements Properties2Keys {
    static { put(prop2Key, "Test2"); }
    public interface Properties2Keys {
    public final static String prop2Key = "prop2";
    Now, if the first thing we do is Properties2.get(Properties2.prop2Key) we will get a (null,) because no fields or methods from Properties2 have been accessed, and the static initializer is not executed.
    How can we automatically force Properties2 static initialization without either declaring some dummy method to be called first or reimplementing Properties1 methods. Properties1 is extended to import it's keys. Implementing Properties1Keys is not an option because further subclasses of this will need to implement all the stuff above it. This would be the most elegant solution (I think) but it fails to initialize because of the VM spec.
    Is the only solution a semi-screwy singleton?

    Interesting problem. Here's the setup:Unless I am reading something wrong that code makes absolutely no sense.
    public class Properties1 This class has a static initializer. Static initializers are called when the class is loaded. Static initializers have nothing to do with instances of the class. Just as static methods have nothing to do with instances of a class.
    The static initializer in Properties1 is calling a member variable. A variable that does not even exist in the context of a static initializer. That should be all that needs to be said on the subject.
    Lets presume that ht should have been static (since everything else is static.)
    When the class Properties2 is loaded one of the first things that occurs is that the parent classes are also loaded. Thus Properties1 is loaded. And likewise Properties1Keys is loaded.
    When Properties1Keys is loaded, it assigns the value to prop1Key. Thus when the static initializer of Propperties1 runs, prop1Key will have a value.
    Perhaps the problem lies in thinking that the values are initialized when the methods are accessed rather than when the classes are loaded?
    And in actual point of fact, because the values are declared 'final' it does not matter if prop1Key is initialized or not. Because the compiler will have already optimized the variable away. Consequently the code will be doing basically the following:
    static { ht.put("prop1", "Test1"); }
    This is relevant if the interface Properties1Keys changes and all of the dependent classes are not rebuilt. The values will not match.

  • JSP behavior - static initializer and jspInit

    In a recent discussion, the concept of using a static intializer in a JSP came up. The situtation was that someone had a series of Strings used in a single JSP and they wanted to #1, define these strings in the JSP itself (vs in web.xml or a resource file, which while preferable, was not really an item of discussion) and #2 wanted indexed access to the Strings (such as via a Map).
    My thought was to declare the Map variable as static final in the JSP and then initialize it in a static initializer block with Map.put operations. Both the declaration of the Map and the static initializer block would be declared in a <%! %> declaration tag block. (The thought behind the static initialization - vs overriding jspInit - being that if multiple instances of the JSP were to be created, we wouldn't want to keep put'ing values into the Map for each new instance of the JSP.)
    I built the following test scenario:
    <<untitled3.jsp source>>
    <%@ page import="java.util.*" %>
    <%!
    static final Map m = new HashMap();
    static int staticCount = 0;
    static int jspInitCount = 0;
    static {
    System.out.println("static initializer called");
    staticCount++;
    m.put("staticCount"+staticCount, "static# " + staticCount);
         public void jspInit() {
              super.jspInit();
    jspInitCount++;
    m.put("jspInitCount"+jspInitCount, "jspInit# " + jspInitCount);
    System.out.println("overriden jspInit called:" + this);
    %>
    Map values:<br>
    <%
    Collection values = m.values();
    Iterator i = values.iterator();
    while (i.hasNext()) {
    out.println(i.next().toString() + "<br>");
    %>
    Test
    <<end of untitled3.jsp source>>
    with the following web.xml entries:
    <servlet>
    <servlet-name>JSPServlet1</servlet-name>
    <jsp-file>untitled3.jsp</jsp-file>
    </servlet>
    <servlet>
    <servlet-name>JSPServlet2</servlet-name>
    <jsp-file>untitled3.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
    <servlet-name>JSPServlet1</servlet-name>
    <url-pattern>/jsp1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>JSPServlet1</servlet-name>
    <url-pattern>/jsp2</url-pattern>
    </servlet-mapping>
    I open a browser and request untitled3.jsp, I get the following output in the browser:
    Map values:
    static# 1
    jspInit# 1
    Test
    with the following output to my JDeveloper (9.0.3.1) log window:
    static initializer called
    overriden jspInit called:_untitled3@61
    I then request /jsp1 and get the following output in the browser:
    Map values:
    static# 1
    jspInit# 2
    jspInit# 1
    Test
    with the following output to my log window:
    overriden jspInit called:_untitled3@63
    Subsequent calls to /jsp1, /jsp2 or untitled3.jsp result in that same last output in the browser and no further output in the log window (ie, no further calls to the static initializer or jspInit method)
    So, it appears that jspInit is being called once for the unmapped JSP request and one more time, the first time one of the web.xml-mapped JSP instances is requested. (I'd have thought that it would be called once for the /jsp1 request and once for the /jsp2 request...), but the static initializer is being called only once as expected.
    Is this the correct behavior for the jspInit method? (ie, being called once for the unmapped request and once for the first mapped request?)
    Also, if OC4J is used in a clustered/balanced configuration, is it possible that I'd end up with additional instances of my JSP in one or more JVMs?
    Thanks!
    Jim Stoll

    You could scope such info to the application scope - some info is provided here: http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html
    "application - You can use the Bean from any JSP page in the same application as the JSP page that created the Bean. The Bean exists across an entire JSP application, and any page in the application can use the Bean."

Maybe you are looking for

  • A network cable is NOT unplugged, need help

    So my internet appears to be working fine but yesterday I was playing a game (world of warcraft) and my latency jumped from the normal 200ms to about 800ms. It appears to be jumping back and forth 200 to 800 but I can't tell for sure. I closed the ga

  • Logic on a dual 1ghz processor machine.

    I have a quicksilver dual 1ghz processor machine with 1.5gig ram. The minimum requirement for Logic is a single 1.25ghz processor. It would "seem" like a dual 1ghz processor board would trumph a single 1.25ghz processor. I went to the local Apple sto

  • My iPhone cannot finish the sync process

    Hey guys, I was not sure whether there are German guys reading my problem so I decided to ask again but this time in English. My problem is that my Iphone 6 plus 64 gb is not able to complete the sync process when I try to synchronize it with my Mac

  • How to create a reusable worksheet/questionnaire?

    HI, I'm trying to make some worksheet/questionnaire templates where the questions (and the format of the document) are un-editable. Something I can open up at a later time, tab though the questions and fill in the blanks as needed, then save the comp

  • Help needed to handle buttons in the screen

    hi i have two buttons in my screen say button1 and button2 by default when i display this screen as per my requirement only button1 should be visible and button2 should be invisible button2 should only be visible when i click on my first button i.e.