You can manually force disconnection by a Thread sleep. This is an example:
URLConnection con = url.openConnection();
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
new Thread(new InterruptThread(con)).start();
then
public class InterruptThread implements Runnable {
HttpURLConnection con;
public InterruptThread(HttpURLConnection con) {
this.con = con;
}
public void run() {
try {
Thread.sleep(5000); // or Thread.sleep(con.getConnectTimeout())
} catch (InterruptedException e) {
}
con.disconnect();
System.out.println("Timer thread forcing to quit connection");
}
}