Connection timeout for DriverManager getConnection

后端 未结 6 1949
梦毁少年i
梦毁少年i 2020-11-29 01:23

I am trying to connect to DB using the standard JDBC way

connection = DriverManager.getConnection(url, username, password);

Is there a maxi

6条回答
  •  臣服心动
    2020-11-29 02:24

    You can use ExecutorService interface from Java. Below is a sample of what you need to do.

    Future future = executor.submit(YOUR_METHOD);
    future.get(TIMEOUT_YOU_NEED, TimeUnit.SECONDS);
    

提交回复
热议问题