This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 221602
Collapse All | Expand All

(-)a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java (-1 / +35 lines)
Lines 56-61 Link Here
56
import java.sql.SQLWarning;
56
import java.sql.SQLWarning;
57
import java.text.MessageFormat;
57
import java.text.MessageFormat;
58
import java.util.*;
58
import java.util.*;
59
import java.util.concurrent.Callable;
60
import java.util.concurrent.ExecutionException;
61
import java.util.concurrent.ExecutorService;
62
import java.util.concurrent.Executors;
63
import java.util.concurrent.Future;
64
import java.util.concurrent.TimeUnit;
65
import java.util.concurrent.TimeoutException;
59
import java.util.logging.Level;
66
import java.util.logging.Level;
60
import java.util.logging.Logger;
67
import java.util.logging.Logger;
61
import org.netbeans.api.db.explorer.DatabaseException;
68
import org.netbeans.api.db.explorer.DatabaseException;
Lines 288-294 Link Here
288
            if (LOGGER.isLoggable(Level.FINE) && warnings != null) {
295
            if (LOGGER.isLoggable(Level.FINE) && warnings != null) {
289
                LOGGER.log(Level.FINE, "Warnings while trying vitality of connection: " + warnings);
296
                LOGGER.log(Level.FINE, "Warnings while trying vitality of connection: " + warnings);
290
            }
297
            }
291
            return ! conn.isClosed();
298
            return ! checkClosedWithTimeout(conn);
292
        } catch (Exception ex) {
299
        } catch (Exception ex) {
293
            if (dbconn != null) {
300
            if (dbconn != null) {
294
                try {
301
                try {
Lines 302-307 Link Here
302
        }
309
        }
303
    }
310
    }
304
    
311
    
312
    private static boolean checkClosedWithTimeout(final Connection connection) {
313
        ExecutorService executor = Executors.newCachedThreadPool();
314
        Callable<Boolean> task = new Callable<Boolean>() {
315
            @Override
316
            public Boolean call() {
317
                try {
318
                    return connection.isClosed();
319
                } catch (SQLException ex) {
320
                    LOGGER.log(Level.FINE,
321
                            "While trying vitality of connection: " //NOI18N
322
                            + ex.getLocalizedMessage(), ex);
323
                    return false;
324
                }
325
            }
326
        };
327
        Future<Boolean> future = executor.submit(task);
328
        try {
329
            return future.get(1, TimeUnit.SECONDS);
330
        } catch (TimeoutException e) {
331
            return false;
332
        } catch (InterruptedException e) {
333
            return false;
334
        } catch (ExecutionException e) {
335
            throw new RuntimeException(e);
336
        }
337
    }
338
305
    public static boolean test(Connection conn, String connectionName) {
339
    public static boolean test(Connection conn, String connectionName) {
306
        try {
340
        try {
307
            if (! isVitalConnection(conn, null)) {
341
            if (! isVitalConnection(conn, null)) {

Return to bug 221602