Package org.postgresql
Class Driver.ConnectTask
- java.lang.Object
-
- org.postgresql.Driver.ConnectTask
-
- All Implemented Interfaces:
java.lang.Runnable
- Enclosing class:
- Driver
private static class Driver.ConnectTask extends java.lang.Object implements java.lang.RunnablePerform a connect in a separate thread; supports getting the results from the original thread while enforcing a login timeout.If the caller times out or is interrupted, we mark the attempt as abandoned and try to cancel the worker thread. Cancellation is best-effort: if the connection attempt does not stop immediately, the worker closes any connection it manages to establish after abandonment so that it does not leak.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanabandonedprivate java.util.concurrent.atomic.AtomicReference<java.sql.Connection>establishedConnectionprivate java.util.concurrent.FutureTask<java.sql.Connection>futureTask
-
Constructor Summary
Constructors Constructor Description ConnectTask(java.lang.String url, java.util.Properties props)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidabandon()private static voidcloseConnection(java.sql.Connection conn)(package private) java.sql.ConnectiongetResult(long timeout)Get the connection result from this (assumed running) task.voidrun()
-
-
-
Method Detail
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
getResult
java.sql.Connection getResult(long timeout) throws java.sql.SQLExceptionGet the connection result from this (assumed running) task. If the timeout is reached without a result being available, a SQLException is thrown.- Parameters:
timeout- timeout in milliseconds- Returns:
- the new connection, if successful
- Throws:
java.sql.SQLException- if a connection error occurs or the timeout is reached
-
abandon
private void abandon()
-
closeConnection
private static void closeConnection(java.sql.Connection conn)
-
-