I have the following code:
public class Net {
    public static void main(String[] args) {        
        Runnable task = new Runnable() {            
            @Override
            public void run() {
                String host = "http://example.example";
                try {
                    URL url = new URL(host);
                    StringBuilder builder = new StringBuilder();                    
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();
                    try(BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {  
                        String line;
                        while (null != (line = in.readLine())) builder.append(line);
                    }           
                    out.println("data: " + builder.length());
                    con.disconnect();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        Thread thread = new Thread(task);
        thread.start();
        thread.interrupt();
    }
}
This "con.getInputStream()" blocks thread, when host is wrong. How to interrupt this code from another thread?
 
     
     
    