7 Ответы Последний ответ: 25.03.2009 1:00, автор: alwu-Oracle

    java.lang.Shutdown and Jena connections

    652134
      System Specs:
      Oracle 11.1.0.6.0
      Oracle Jena Drivers Release 2
      Jena 2.5.6
      Java 1.5
      Web Server: Glassfish

      Hello,
      We are running a web application against our Oracle database. We are using the Jena drivers to open SPARQL queries. Recently we started seeing some Java Heap memory exceptions on our glassfish server. We dumped the java heap hprof file. We then analyzed the contents. Within the Heap there is an object called java.lang.Shutdown. This object maintains a HashMap of references of object that the JVM will cleanup once the web server is shutdown. It appears that this list accumulates oracle.spatial.rdf.client.jena.Oracle$1. According to the heap tool, there are 5000 of these objects accumulated in the java.lang.Shutdown. Is there a way to free these up programmatically (or avoid registering them with the java.lang.Shutdown)? I believe I am correctly closing the Oracle connections. I do not see any active Oracle JDBC connections on the server.

      Thanks,
      Chuck
        • 1. Re: java.lang.Shutdown and Jena connections
          alwu-Oracle
          The current logic in Oracle constructor is that we add a shutdown hook so that unfinished transaction can be rolled back when VM shuts down.

          You mentioned that there has been an accumulation of 5000 Oracle objects. Could you please describe a typical end-to-end flow? Was a new Oracle instance created for every incoming request?
          • 2. Re: java.lang.Shutdown and Jena connections
            652134
            Hi Alan,
            Thanks for the quick reply. Yes, a new Oracle instance is created for every request. I created a wrapper class (SparqlConnection) for the oracle.spatial.rdf.client.jena.Oracle object. The wrapper contains an attribute of type Oracle.

            1) my constructor contains this code:
            oracle = new Oracle(jdbcUrl, user, password);

            2) SparqlConnection executes the query

            3) When the query is done call close() method. The close() code looks like:

            try {
            if (oracle != null) {
            oracle.dispose();
            }
            } catch (Exception e) {
            System.out.println("Error closing Oracle connection. Error: " + e.getMessage());
            e.printStackTrace(System.out);
            } finally {
            oracle = null;
            }


            Is there a connection pooling class or do I need to create my own? When you say "we add a shutdown hook so that unfinished transaction can be rolled back when VM shuts down" are these hooks only added when the executed statement is an INSERT/UPDATE/DELETE? Or is the hook added for SELECT statements also?

            Thanks,
            Chuck
            • 3. Re: java.lang.Shutdown and Jena connections
              alwu-Oracle
              Shutdown hook is created when an Oracle instance is constructed.

              Connection pooling is usually provided by a J2EE container. Your JDBC library might have some pooling capabilities.

              I can provide you a patch that does not register shutdown hooks. Please email me at alan dot wu at oracle dot com.

              However, it is not a good idea to create a brand new Oracle object (a new DB connection) to serve each and every new request.
              • 4. Re: java.lang.Shutdown and Jena connections
                652134
                I will create a connection pool for my Oracle connections. That should help. However, I have two other questions:

                1. Is a hook created for the SELECT statements? If so, is this really necessary? Does a SELECT statement need to be rolled back when the JVM shutsdown?
                2. If the hook is created for each Oracle connection, does calling commitTransaction() remove the hook?

                Thanks,
                Chuck
                • 5. Re: java.lang.Shutdown and Jena connections
                  alwu-Oracle
                  Hook is not created for SELECT statements. It is per Oracle instance to make sure when some unexpected error happens, the underlying connection is rolled back.

                  commitTransaction will not remove the hook because after you commit one transaction, you may start
                  a new one using the same Oracle instance. For example, assume one builds an ontology editing tool. After editing an ontology for a while, a user may choose to "save" (commit) his/her changes. More editing can follow obviously. Note however, the very same Oracle instance is used to avoid re-establishing a DB connection.
                  • 6. Re: java.lang.Shutdown and Jena connections
                    691732
                    Can you please clarify exactly when the shutdown hook is registered? I understand that you say it is registered when the Oracle instance is created. There are two different constructors for this class, one of which takes an existing Oracle JDBC connection and the other of which takes a JDBC URL, username, and password. Will both constructors cause the shutdown hook to be registered? Thanks in advance.
                    • 7. Re: java.lang.Shutdown and Jena connections
                      alwu-Oracle
                      Yes. Both constructors will register the shutdown hook.

                      BTW, Chuck is happy with the version that has shutdown hook logic removed.