7 Replies Latest reply on Mar 25, 2009 1:00 AM by alwu-Oracle

    java.lang.Shutdown and Jena connections

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

      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.

        • 1. Re: java.lang.Shutdown and Jena connections
          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
            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) {
            } catch (Exception e) {
            System.out.println("Error closing Oracle connection. Error: " + e.getMessage());
            } 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?

            • 3. Re: java.lang.Shutdown and Jena connections
              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
                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?

                • 5. Re: java.lang.Shutdown and Jena connections
                  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
                    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
                      Yes. Both constructors will register the shutdown hook.

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