title: Java get result from Thread and Runnable
body: <p>in this below code i can not get result from <code>getValue</code> from <code>Foo</code> class and thats return <code>null</code> but that must be return value. result is correct and this function could not return that. for example this is my class:</p>
  
  <pre><code>public class JsonService {
      private JSONObject json = new JSONObject();
      public JsonService(final String username, final String password) throws Exception{
          json.put("username", username);
          json.put("password", password);
      }
      public class Foo implements Runnable {
          private String result;
  
          @Override
          public void run() {
              HttpClient client = new DefaultHttpClient();
              HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
              HttpResponse response;
  
              try {
                  HttpPost post = new HttpPost("http://www.example.com/json_android.php");
                  StringEntity se = new StringEntity( json.toString());
                  se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                  post.setEntity(se);
                  response = client.execute(post);
                  if(response!=null){
                      InputStream stream = response.getEntity().getContent();
                      result = convertToString(stream);
  
                      /*
                           I can Log result with below line
                      */
                      Log.e("response is: ", result);
  
                      /*
                           result is {"username = ":"Hello"}
                      */
                  }
              } catch(Exception e) {
                  e.printStackTrace();
                  Log.e("Error", String.valueOf(e));
              }
          }
  
          public String getValue() {
              /*
                   return in this fucntion not working
              */
              return result;
          }
      }
      public String request() throws ExecutionException, InterruptedException {
          Foo foo = new Foo();
          new Thread(foo).start();
          return foo.getValue();
      }
  </code></pre>
  
  <p>How to get result correctly from <code>Foo</code> and return that from <code>reauest()</code> ? please help me. thanks</p>