publicclassDriverManager{ // List of registered JDBC drivers privatefinalstatic CopyOnWriteArrayList<DriverInfo> registeredDrivers = new CopyOnWriteArrayList<>(); // 该变量被声明为 static, 导致其他类型的数据源设置了 DriverManager 中的该变量后,Hive JDBC 将会使用到其他类型数据源设置的超时时间 privatestaticvolatileint loginTimeout = 0; privatestaticvolatile java.io.PrintWriter logWriter = null; privatestaticvolatile java.io.PrintStream logStream = null; // Used in println() to synchronize logWriter privatefinalstatic Object logSync = new Object();
/* Prevent the DriverManager class from being instantiated. */ privateDriverManager(){}
/** * Sets the maximum time in seconds that a driver will wait * while attempting to connect to a database once the driver has * been identified. * * @param seconds the login time limit in seconds; zero means there is no limit * @see #getLoginTimeout */ publicstaticvoidsetLoginTimeout(int seconds){ loginTimeout = seconds; }
/** * Gets the maximum time in seconds that a driver can wait * when attempting to log in to a database. * * @return the driver login time limit in seconds * @see #setLoginTimeout */ publicstaticintgetLoginTimeout(){ return (loginTimeout); }
/** * Enable/disable {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} * with the specified timeout, in milliseconds. With this option set * to a non-zero timeout, a read() call on the InputStream associated with * this Socket will block for only this amount of time. If the timeout * expires, a <B>java.net.SocketTimeoutException</B> is raised, though the * Socket is still valid. The option <B>must</B> be enabled * prior to entering the blocking operation to have effect. The * timeout must be {@code > 0}. * A timeout of zero is interpreted as an infinite timeout. * * @param timeout the specified timeout, in milliseconds. * @exception SocketException if there is an error * in the underlying protocol, such as a TCP error. * @since 1.1 * @see #getSoTimeout() */ publicsynchronizedvoidsetSoTimeout(int timeout)throws SocketException { if (isClosed()) thrownew SocketException("Socket is closed"); if (timeout < 0) thrownew IllegalArgumentException("timeout can't be negative");