[hg] main-silver: #221602: Hanged when trying to stop database q...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #221602: Hanged when trying to stop database q...
  • Date: Fri, 16 Nov 2012 10:27:23 -0800

changeset 829141218633 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/829141218633
description:
        #221602: Hanged when trying to stop database query on Oracle database

diffstat:

 db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java |  37 
+++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diffs (61 lines):

diff --git a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java 
b/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java
--- a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java
+++ b/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java
@@ -56,6 +56,11 @@
 import java.sql.SQLWarning;
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.netbeans.api.db.explorer.DatabaseException;
@@ -288,7 +293,7 @@
             if (LOGGER.isLoggable(Level.FINE) && warnings != null) {
                 LOGGER.log(Level.FINE, "Warnings while trying vitality of 
connection: " + warnings);
             }
-            return ! conn.isClosed();
+            return !checkClosedWithTimeout(conn);
         } catch (Exception ex) {
             if (dbconn != null) {
                 try {
@@ -302,6 +307,36 @@
         }
     }
     
+    /**
+     * Check whether a connection is closed, using a reasonable timeout. See 
bug
+     * #221602.
+     */
+    private static boolean checkClosedWithTimeout(final Connection 
connection) {
+        Callable<Boolean> task = new Callable<Boolean>() {
+            @Override
+            public Boolean call() {
+                try {
+                    return connection.isClosed();
+                } catch (SQLException ex) {
+                    LOGGER.log(Level.FINE,
+                            "While trying vitality of connection: " //NOI18N
+                            + ex.getLocalizedMessage(), ex);
+                    return false;
+                }
+            }
+        };
+        Future<Boolean> future = RP.submit(task);
+        try {
+            return future.get(1, TimeUnit.SECONDS);
+        } catch (TimeoutException e) {
+            return false;
+        } catch (InterruptedException e) {
+            return false;
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     public static boolean test(Connection conn, String connectionName) {
         try {
             if (! isVitalConnection(conn, null)) {

[hg] main-silver: #221602: Hanged when trying to stop database q...

Jaroslav Havlin 11/16/2012

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close