The only general solution to this problem is to have a separate thread where you try to get the connection. You can set a timeout to complete the task of getting that connection. In java, FutureTask can be used to accomplish this:
Connection connection;
FutureTask task = null;
try {
task = new FutureTask(new Callable() {
@Override
public Connection call() throws Exception {
return DriverManager.getConnection(url, username, password);
}
});
new Thread(task).start();
connection = task.get(getConnectionTimeout(), TimeUnit.SECONDS);
} catch (Exception e) {
throw new ConnectionException("Could not establish connection.", e);
}
Great Article android based projects
ReplyDeleteJava Training in Chennai
Project Center in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training