PreparedStatement.close() hangs, blocking finalization

We encountered an incident on a production system with a class that would call PreparedStatement.close() on finalize(), and there was an instance where the jvm finalizer thread stalled on this the PreparedStatement.close() call, blocking garbage collection.
The last sql statement run with the preparedstatement was most probably a select statement (we cannot determine for sure), and the OCI driver was used.
While I realize it's not recommended to close PreparedStatements on finalize(), can I ask for some possible reasons why the close() call would stall? Would it be a database issue or a java issue?

Can you do the close() in a PhantomReference? That might be a good alternative to using finalize(). These refs are rather obscure and most Java authors parrot the usual line about post-mortem cleanup, but if you dig deep enough you can find a few examples of its use (I think that there is Apache group source with an example).
If you are running in a servlet, move the close() to the servlet destroy() method.
The best solution is to use 10.2 implicit connection caching and close all your Connections immediatly after use in a finally block. Then close your DataSource in the destroy().

Similar Messages

  • PreparedStatement.Close()

    I'm using the same PreparedStatement object for many querys on a method, I think this is ok, isn't it? So... Do I need to call the PreparedStatement.close() method between every query? Can I call the close method many times without calling the executeQuery() method?
    Thanks
    Eduardo Castor

    Do not close the PreparedStatement until your program ends (or until you do not need it any more). You can use it repeatedly without closing it.

  • TLS.close() hangs forever.

    Hi,
    i am facing a problem while trying to connect to Sun One Dir Server using TLS Connection. When ever i connect to the Sun Dir Server using TLS and , when i try to close the TLS connection using the TLS.close() API, the control never returns back from this API. In other words TLS.Close() hangs forever.
    Does any one know why this happens ??
    Please help me to get over this, Thanks in advance
    -pele

    Try this ,
    Open the itunes ,
    Click on the left-side on ur ipod icon ,
    Then click on the top on summary ,
    Then click on the manual selection , an
    option will appear if u click on the
    any left side icon on the library ,
    Then click on apply on that option
    then u can select ur items by 1 by 1
    manually.
    NOTE : IF U CAN'T SLECT THE MANUAL SELECTION
    THEN TRY TO FIRST DESELECT THE OTHER
    OPTION ON THE ABOVE AND BELOW OF IT ,
    THEN SELECT THE DESELECTED ITEM IF U WANT
    OK
    HAVE A NICE DAY

  • Servlet crashes on preparedStatement.close()

    Hello Everyone ,
    I have a servlet that gives out database information. Depending on the request parameters , some prepared statements that I declare before my try block may or may not be used. All statements and resultSets are initialized to null. If I determine the request is bad my servlet goes to an else block, then the finally block to close statements and stuff. Unfortunately, when it hits a preparedStatement that wasn't used, it outputs a HTTP Status 500 java.lang.NullPointer exception. I have never had this happen before ?
    P.S I output my xml before the try block, so how come I see the error and not my xml, or a combination of both ?

    As mentioned earlier by others, in your servlet code somewhere you are doing some operation on an object which is null. From server error log see the stack trace. Locate the exact place of NullPointerException and fix it.
    I hope you know where log files are generated in server. If you need help fixing the root cause of NullPointerException please post your code snippet here.
    Thanks,
    Mrityunjoy

  • Inet4AddressImpl.lookupAllHostAddr(String) hangs/blocks

    I'm experiencing a hang when attempting to establish a socket connection.
    Debugging indicates the VM is blocked here:
    Inet4AddressImpl.lookupAllHostAddr(String) line: not available [native method]
    I'm experiencing this problem during an ANT build.
    Interestingly the problem disappears if I execute the offending code in a forked process.
    Consequently, I suspect this may be a bug in the VM implementation.
    Can anyone offer any insights into why the hang is occurring?
    Kind Regards,
    Matthew

    Which operating system do you see this with? If Windows then it may be a locking issue between pipe connection between ANT and child process and the host lookup. Here is the bug tracking the issue (looking at the referenced bugs to see other examples:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4653680
    The problem has been investigated many times and requires a fix in Windows (can't be fixed or worked around in the JDK).

  • Should PreparedStatement close before continue next PreparedStatement ?

    Hi guys,
    For instance, I need to use PreparedStatement for several insert and update like below:
    Connection conn; // got the connection
    PreparedStatement pstmt = conn.prepareStatement("insert ......");
    pstmt.addBatch();
    pstmt.executeBatch();
    *// should I do a pstmt.close() here ?????????*
    pstmt = conn.prepareStatement("update......");
    pstmt.addBatch();
    pstmt.executeBatch();
    Thanks & Regards,
    Mark

    kmthien wrote:
    Yes, I am using apache DBCP and using the example code here :
    http://www.freshblurbs.com/jakarta-commons-dbcp-tutorial#comment-544
    However, In my class, I need to connect to 2 database, 1 is local and another 1 is remote.Location doesn't matter.
    I don't know how to create and initialize 2 connection pooling as when I initialize 2 connection pooling, it jus treated it as 1 only.This is of course completely different from your first question. Did you google?

  • DataInputStream.close() is blocking while closing the thread's stream.Why?

    I have a DataInputStream in my thread as
    DataInputStream dis = new DataInputStream(System.in);
    I have written a method for closing that DataInputStream as
    public void closeStream(){
    dis.close();
    But when I call closeStream method from my program as
    t.closeStream();
    it blocks the program execution. I have to press 'Enter' to continue.
    Why is it so?
    Thanx in Advance.

    You're creating the DataInputStream around the standard input. Assuming you haven't reassigned System.in, I'm pretty sure that you can't close it. At least, you shouldn't be able to close the standard input.

  • Close a blocking wait thrad by another thread

    Hi all
    I have a lookup method which makes a blocking wait and I want to close this lookup if the content not available for 10 seconds.
    What I have done is put this lookup in a thread(LookupThread) and used separate thread(TimeCheckThread) for calculate the elapsed time.
    This is my idea
    public class LookupThread extends Thread
        Calendar cal = Calendar.getInstance();
        boolean closed = false;
        public TimeCheckThread getTimeChecker()
            return new TimeCheckThread();
        public void run()
            lookMethod(); // this is the blocking wait
        public class TimeCheckThread extends Thread
            long startTime = cal.getTimeInMillis();
            public void run()
                // strted looking for elapsed time
                while(true)
                    cal = Calendar.getInstance();
                    if(cal.getTimeInMillis()-startTime > 10000 & !closed)
                        // if 10 seconds elapsed close the thread which makes the blocking wait
                        LookupThread.super.stop();
                        closed = true;
                        // to exit from time check thread
                        break;
        public static void main(String args[])
            LookupThread v = new LookupThread();
            v.getTimeChecker().start();
            v.start();
    }The problem is closing of thread is deprecated.
    LookupThread.super.stop();So any idea to handle those blocking wait situations and assign a return time other than this approach?

    WirajR wrote:
    Also TimeCheckThread eats of CPU time for 10 seconds use a java.util.Timer instead
    >Also TimeCheckThread eats of CPU time for 10 seconds use a java.util.Timer instead
    Hi
    I think this is the most suit to my requirement. Totally different way, but acceptable.
    To EJP
    Ur solution seems great to replace following code segment
    public class TimeCheckThread extends Thread
            long startTime = cal.getTimeInMillis();
            public void run()
                // strted looking for elapsed time
                while(true)
                    cal = Calendar.getInstance();
                    if(cal.getTimeInMillis()-startTime > 10000 & !closed)
                        // if 10 seconds elapsed close the thread which makes the blocking wait
                        LookupThread.super.stop();
                        closed = true;
                        // to exit from time check thread
                        break;
        }like following
    public class TimeCheckThread extends Thread
           public void run()
                        TimeCheckThread.sleep(10000);
                        LookupThread.super.stop();
    }To Peter__Lawrey
    Why don't you make the blocking lookup block for only 10 seconds?Any idea to implement such blocking lookup block?
    My blocking operation is a looking for RTP video stream. It waits until server sends the video

  • One node RAC pause/hang/block on other node shutdown

    Hi,
    We have a Java application running on Linux servers connecting to a 10.2.0.1 RAC cluster, also Linux. When the application starts it opens up a pool of connections to the databsae, and these are used throughout the life time of the application. One server connects to one RAC node.
    AppA - DBA
    AppB - DBB
    When we shutdown one node, the application connecting to that node stops, which is what we would expect in this configuration.
    What is strange is that the other application blocks for 63 seconds and then continues. So it is like the database is blocking, or the database connections are blocking.
    We are not using TAF, FAN, FCN, LB, VIPs or any special features, just simple lightweight JDBC from one server to one database. In fact I do not thing we are unwittingly using any of these features, we have them switched off.
    john

    user1788323 wrote:
    What is strange is that the other application blocks for 63 seconds and then continues. So it is like the database is blocking, or the database connections are blocking.How have you determined/diagnosed the 63s blocking? (more details in this regard may shed some light on the problem)
    Assuming that the block is server side, then two basic reasons comes to mind.
    Networking issue - the CRS on the surviving node has to perform certain functions, like switching the VIP of the node that left the cluster to a surviving cluster node. The listener may need to re-register services. A local firewall may need to be dynamically reconfigured for supporting the new failed-over VIP. Etc.
    Thus these could result in some kind of delay or issue in the network layer that you are seeing from the client side.
    Infrastructure issue. If the actual client request via JDBC reaches the server process, and it is slow in responding, then that is not a network issue - instead some underlying service or s/w layer that the server process needs to use to perform the client request is busy for those 63s.
    This could be related to the Interconnect, the shared I/O storage layer or something along those lines. For example, how does the Interconnect and/or SAN switch re-act when a server node is powered down or rebooted?
    There's not really sufficient information to make anything but a guesses.. You will need to isolate the problem with further testing.
    I have seen similar problems with 10.1.0.3 CRS and RAC when a node is evicted from the cluster. In this case the "hung" period was in excess of 15 minutes and only for new connections (Listener unable to hand off to dedicated servers or dispatchers). Existing connections worked fine however and were unaware of any problems. But part of the issue in this case was a poor (outdated) driver layer - and also the last time we used proprietary binary drivers (kernel modules) from 3rd party vendors that results in a tainted (and very fixed and rigid) Linux kernel. Today we're sticking with an OpenSource driver layer only for Linux.

  • 9.2.0 Thin driver; PreparedStatement.close() gives NullPointerException when close()d

    Here's the error stack:
    --- Nested Exception ---
    java.lang.NullPointerException
    at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:431)
    at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:3528)
    at oracle.jdbc.driver.OraclePreparedStatement.clearParameters(OraclePreparedSta
    at com.secretseal.util.sql.PooledPreparedStatement.close(PooledPreparedStatemen
    at com.secretseal.util.sql.LoggableStatement.close(LoggableStatement.java:112)
    Has anybody has this issue? Thank you in advance.

    workaround: use Oracle proprietary batching, setExecuteBatch(). My webapp is facing the exact problem. But I used the Oracle 8i drivers and it worked. Meanwhile, will you please tell me what is the AppServer you are using? Cause this happens in Websphere 4.0.x environment but not in 3.5.x and weblogic.
    Thanks,

  • When to use PreparedStatement.close()

    Hi,
    For a long time I was/am convinced that it is good to use prepared statement eventhough you are not going to use them propertly, cause whenever in the future you are going to modify your code to use your connections wisely along with prepared statements it will save you valuble execution time.
    I have following enviornment....
    Miscrosoft SQL Server 2000 driver for JDBC
    Jakarta-Commons DBCP (have prepared stmt pooling on)
    Tomcat as the web app.
    (I would not like to use Tomcat's internal CPooling cause we may have to migrate to some other app server and then the installation process and everything should have been changed.)
    Now to the actuall question.... in a transacation I have 2 to 3 different sets of queries (some SELECTs, some UPDATEs and some INSERTs)
    say I have QUERY1 , a SELECT query and QUERY2 an UPDATE query in a transaction T1. Will following code utilize features of PreaparedStatement properly??
    String q1 = QUERY1;
    String q2 = QUERY2;
    PreparedStmt pStmt = null;
    pStmt = conn.prepareStatement(q1);
    rs = pStmt.executeQuery();
    Object obj1 = processRS (rs);
    pStmt = conn.prepareStatement(q2);
    myint = pStmt.executeUpdate();
    pStmt.close();Do I need to have "pStmt.close()" btw "Object obj1 = processRS (rs);" and "pStmt = conn.prepareStatement(q2);"?
    Thanks a lot.

    >>
    Do I need to have "pStmt.close()" btw "Object obj1 =
    processRS (rs);" and "pStmt =
    conn.prepareStatement(q2);"?Yes.
    And you need to close the ResultSets as well.
    And you need proper exception handling to handling
    closing all of them if an exception occurs.
    Won't "pStmt.close()" will also close the result set if any?
    And yes I am aware that I need to take care of closing it properly in case of any exception.
    Thanks a lot for your response.

  • How to close non blocking sockets

    Hello!
    I need your help with this. I'm writing a little server(ServerSocketChannel), versy simple, receives data, maskes some fast analisis, and stores it. However, the client make little transmissions and the close the connections. How can I detect a clsoe event with the select keys?. And how can I close the server?

    You will get an OP_READ, and when you do the read it will return -1, whereupon you close the channel.

  • Help! Scriptui close method blocks interraction:

    I am not new to Scripting Indesign but have opted to use the normal dialog options till now and am a little confused by several of the scriptui methods.
    I first attempted to search this forum but the few examples I found were rather vague so I appeal to you now.
    It seems that when I call the close() method on a scriptui dialogs ok or cancel event, it merely hides the object.
    The hidden object (dialog) prevents execution of any script; (ie: app.documents.add();)
    and returns the following error:
         Error: Cannot handle the request because a modal dialog or alert is active.
    Can anyone provide a clear and precise example of closing a script ui dialog then creating a simple document without interference?
    This may benefit others besides me who are finally making the move into the scriptui universe.
    Oh to have CS5 and Flex throughout my company instead of CS4 and scriptui !

    I was able to find a good example for this question from an old script by Dave Saunders:
    http://jsid.blogspot.com/2007/08/scriptui-dialog-with-interacting.html
    //DESCRIPTION: Sample Dialog
    myDlg = new Window('dialog', 'Example');
    myDlg.orientation = 'row';
    // Add action buttons
    myDlg.btn1 = myDlg.add('button', undefined, 'Disable Him');
    myDlg.btn2 = myDlg.add('button', undefined, 'Disable Him');
    myDlg.closeBtn = myDlg.add('button', undefined, 'Close');
    // Add button functions
    myDlg.btn1.onClick = function() {
      if (this.text == 'Disable Him') {
        this.text = 'Enable Him';
        myDlg.btn2.enabled = false;
      } else {
        this.text = 'Disable Him';
        myDlg.btn2.enabled = true;
    myDlg.btn2.onClick = function() {
      if (this.text == 'Disable Him') {
        this.text = 'Enable Him';
        myDlg.btn1.enabled = false;
      } else {
        this.text = 'Disable Him';
        myDlg.btn1.enabled = true;
    myDlg.closeBtn.onClick = function() {
      this.parent.close(1);
    result = myDlg.show();
    if (result == 1) {
      alert("You used the Close button");
      app.documents.add();

  • Finalizer blocks on a jconnect resultset close

    We are using weblogic 6.1 sp6. We encounter a strange problem of weblogic sometimes
    getting outofmemory errors. Stack trace dumps during the problem time shows the
    finalizer thread waiting on a socket read on ResultSet.close.
    Checking connections on Sybase showed that all connections from weblogic were
    idle and were in awaiting command state. Killing the sybase connection for the
    resultset close method enabled finalizer to continue and memory was reclaimed.
    Checking the application code showed that the application had leaked a resultset
    and the connection object, a javap on weblogic.jdbc.pool.ResultSet shows that
    in SP6 the finalize method has been implemented.
    Any ideas or clues what caused this scenario would be very much appreciated.

    kader wrote:
    We are using weblogic 6.1 sp6. We encounter a strange problem of weblogic sometimes
    getting outofmemory errors. Stack trace dumps during the problem time shows the
    finalizer thread waiting on a socket read on ResultSet.close.
    Checking connections on Sybase showed that all connections from weblogic were
    idle and were in awaiting command state. Killing the sybase connection for the
    resultset close method enabled finalizer to continue and memory was reclaimed.
    Checking the application code showed that the application had leaked a resultset
    and the connection object, a javap on weblogic.jdbc.pool.ResultSet shows that
    in SP6 the finalize method has been implemented.
    Any ideas or clues what caused this scenario would be very much appreciated.Not sure if this relevant to your question: we find that if you do not
    close() statements and prepared statements jConnects leaks
    BufferInterval instances. Do you find you have a large number of
    BufferInterval (a jConnect internal class) instances? What is the actual
    cause of the OutOfMemory error?
    Robert

  • Sockets write/close operations hangs application

    Hi!
    I've got a trouble with my web-application. It'a s chat system, that uses Keep-Alive connections for messages output and that recieves messages through another socket.
    Everything is fine with receiving messages. But after message is received, I need to send it to all recepients. So, I use Socket.write() method. If writing is failed, or user is logged off, I use Socket.close().
    Problem is, that sometimes Socket.write() and Socket.close() are blocking their threads.
    How can I avoid such a blocking behaviour?
    If I'll rewrite everything to use not sockets, but socket channels, can it help to solve my problem?
    Thanks.

    If writes are blocking it can only mean that readers aren't reading. Fix that, and forget about the syncrhonization suggestion which is nonsense.
    You can also use NIO in non-blocking mode to avoid blocking in writes, and it does lead to more scalable applications, but be prepared for about a 10x increase in complexity.

Maybe you are looking for

  • Who's been f**king with my JTables

    OK....own up....who's broken all my JTables!?!? I went on holiday 2 months ago (i know....nice holiday!) and have returned this morning to find that my editable JTables no longer work correctly. If i edit a cell and then click on another component, t

  • WorldPay Integration

    Has anybody integrated the WorldPay third party payment servlets within           WebLogic 5.1?           The problem I have is the WorldPay properties file (select.properties)           is not being read. I'm pretty sure it's a classpath problem.   

  • Multiple R/3 source systems to one BI system

    Hi Friends, We are planning to split our SAP R/3 Into Different Servers...one each for different companies. At present we have only one source R/3 System from where we are getting data to BI. If we split it into different source system...............

  • Status after quitting is failed rather than incomplete

    I would like to get the LMS to report Complete/Incomplete if the presentation is quit before quiz and Fail/Pass after the test. Is this possible? I have set the reporting to Complete/Incomplete and the report data to "user access only", but the LMS r

  • How to keep all files in differents browsers

    I use differents browsers how to keep the bookmarks organised in all of them ? Is better url manager or Bookit ? Thanks