title: Java Poll or Listen to URL for response [Java SE]
body: <p>I have a module which requests status(technically a JSON object) from an FHEM server(home automation) using a simple HTTP post.</p>
  
  <p>How can i poll the requestState method so as to continuously listen (like every 125ms) on the URL for changes in status?</p>
  
  <p>[note: i am not using any server, this is a plain Java program called from a Main function.]</p>
  
  <p>To give an illustration:</p>
  
  <pre><code>public static boolean requestState(){
  HttpPost post = new HttpPost("http://localhost:8083/fhem?cmd=jsonlist+device1");
  try{
          HttpResponse response = client.execute(post);
  
          BufferedReader rd = new BufferedReader( 
                     new InputStreamReader(response.getEntity().getContent()));
  
          StringBuffer result = new StringBuffer();
          String line = "";
          while ((line = rd.readLine()) != null) {
              result.append(line);
          }
                      //response is a JSONObject
          JSONObject o = new JSONObject(result.toString());
  
                      //get the status from the JSON object
          System.out.println(o.getJSONObject("Result").get("STATE"));
          String STATE = o.getJSONObject("Result").get("STATE");
                      if(STATE.equals("OPEN"))
                         return false;
                      else
                         return true;
      }
      catch(Exception e){
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>What i would like to achieve is:</p>
  
  <pre><code>keep listening to URL
    parse response to judge the status
    if status == OPEN
      soundAlarm();
  </code></pre>
  
  <p>Thanks in advance!</p>