Guest User

Untitled

a guest
Nov 16th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1.    @Override
  2.     public void onCreate() {
  3.         super.onCreate();
  4.         try {
  5.  
  6.             Thread thread = new Thread() {
  7.                 @Override
  8.                 public void run() {
  9.                     try {
  10.                         while (true) {
  11.                             sleep(2000);
  12.  
  13.                             HttpURLConnection conn = null;
  14.                             InputStream is = null;
  15.                             try {
  16.                                 System.setProperty("http.keepAlive", "false");
  17.                                 URL url = new URL("http://example.com");
  18.                                 conn = (HttpURLConnection)url.openConnection();
  19.                                 is = new BufferedInputStream(conn.getInputStream());
  20.                                 is.close();
  21.                             } catch (Exception ex) {
  22.                             } finally {
  23.  
  24.                                 if (conn != null) {
  25.                                     conn.disconnect();
  26.                                 }
  27.                             }
  28.                         }
  29.                     }catch (Exception e) {
  30.                         e.printStackTrace();
  31.                     } finally {
  32.  
  33.                     }
  34.                 }
  35.  
  36.  
  37.             };
  38.  
  39.             thread.start();
  40.         } catch (Exception e) {
  41.             e.printStackTrace();
  42.         }
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment