title: make java wait until variable changes
body: <p>I want to make my code wait until there is a change anywhere in my class to the variable finaloutcomes. Is there any way to do this? I am carrying this out within an Asynctask, which I posted below. </p>
  
  <pre><code> public HashMap&lt;String,String&gt; checkbetoutcome() {
  
      new LoadAllGamet().execute();
  
      // INSERT CODE HERE
  
      return finaloutcomes;
  
  }
  </code></pre>
  
  <p>ASYNCTASK</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>class LoadAllGamet extends AsyncTask&lt;String, String, String&gt; {
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
  
          }
  
          protected String doInBackground(String... args) {
             // HttpParams httpParameters = new BasicHttpParams();
             // HttpConnectionParams.setConnectionTimeout(httpParameters, 250000);
              //HttpConnectionParams.setSoTimeout(httpParameters, 250000);
              HttpClient client = new DefaultHttpClient();
              HttpPost post = new HttpPost(url_check_bet);
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("param", bet));
             // Log.d("CURRENTITEM", currentitem);
              try {
                  post.setEntity(new UrlEncodedFormEntity(params));
              } catch (IOException ioe) {
                  ioe.printStackTrace();
              }
              try {
                  HttpResponse response = client.execute(post);
                  Log.d("Http Post Responsecxxx:", response.toString());
                  HttpEntity httpEntity = response.getEntity();
                  InputStream is = httpEntity.getContent();
                  JSONObject jObj = null;
                  String json = "";
                  client.getConnectionManager().closeExpiredConnections();
                  try {
                      BufferedReader reader = new BufferedReader(new InputStreamReader(
                              is, "iso-8859-1"), 8);
                      StringBuilder sb = new StringBuilder();
                      String line = null;
                      while ((line = reader.readLine()) != null) {
  
                          if (!line.startsWith("&lt;", 0)) {
                              if (!line.startsWith("(", 0)) {
                                  sb.append(line + "\n");
                              }
                          }
                      }
  
                      is.close();
                      json = sb.toString();
  
                      json = json.substring(json.indexOf('{'));
                  //    Log.d("sbsssssssssss", json);
                      try {
                          jObj = new JSONObject(json);
                      } catch (JSONException e) {
                          Log.e("JSON Parser", "Error parsing data " + e.toString());
                      }
                      allgames = jObj.getJSONArray("bets");
                   //   Log.d("WHAT IS MY ARRAY?", allgames.toString());
  
                         for (Integer i = 0; i &lt; allgames.length(); i++) {
                             HashMap&lt;String,String&gt; statuses = new HashMap&lt;&gt;();
                              JSONObject c = allgames.getJSONObject(i);
                              JSONArray currentbet = c.getJSONArray("bet");
                              Log.d("Single array",currentbet.toString());
  
                             //  Storing each json item in variable
  
                             for (Integer a = 0; a &lt; currentbet.length();a++) {
                                 JSONObject d = currentbet.getJSONObject(a);
                              String Result = d.getString("Result");
                                 String id = d.getString("gid");
                              Log.d("RESULTS",Result);
  
                             statuses.put(id, Result);
                          }
                             allbetsmap.add(i, statuses);
                             Log.d("ddd", statuses.toString());
                             Log.d("AAA", allbetsmap.get(i).toString());
  
  
                         }
  
  
  
                      } catch (Exception e) {
                          Log.e("Buffer Error", "Error converting result " + e.toString());
                      }
  
  
                  }
               catch (IOException e) {
                  e.printStackTrace();
              }
  
  
  
  
              return "";
          }
  
  
  
          @Override
          protected void onPostExecute(String param) {
              Log.d("SIZE",Integer.toString(allbetsmap.size()));
              //ArrayList&lt;Map&lt;String,String&gt;&gt; allbetsmap = new ArrayList&lt;&gt;();
              //ArrayList&lt;Map&lt;String,String&gt;&gt; passtocheck = new ArrayList&lt;&gt;();
  
              if (allbetsmap.size() == passtocheck.size()) {
                  for (int i = 0; i &lt; allbetsmap.size();i++) {
                  if (allbetsmap.get(i).size() == passtocheck.get(i).size()) {
                      String finaloutcome = "won";
                      for (String a : allbetsmap.get(i).keySet()) {
                          String f = allbetsmap.get(i).get(a);
                          if(f.equals("null")) {
                              finaloutcome = "open";
                          }
                          else if (! (f.equals(passtocheck.get(i).get(a)))) {
                              finaloutcome = "lost";
                              break;
                          }
                      }
                      finaloutcomes.put(Integer.toString(i),finaloutcome);
                  }
                  }
  
              }
              Log.d("Vital",finaloutcomes.toString());
  
  
          }
  
  
      }</code></pre>
  </div>
  </div>
  </p>