title: How to return a value from thread in java?
body: <p>In android i am creating thread for url connection.Inside the thread i store the response message in a string which is globally declared.When I access the method method it returns null. </p>
  
  <pre><code>    public class Rate_fetch {
         String total="";
            public String  rate(String dt)
         {
      new Thread(new Runnable(){ 
  
           public void run(){
  
  
              try  {
  
               URL url = new URL(tally_ipaddr+"/prorate.jsp?plist="+sss.toString().trim());
  
               HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
               InputStream in = new BufferedInputStream(urlConnection.getInputStream());
               BufferedReader r = new BufferedReader(new InputStreamReader(in));
               String x = "";
               String total = "";
               x = r.readLine();
               int i=0;
  
               while(x.length()&gt;1)
               {
                   total=total+x.toString().trim();
                   i++;
                   x = r.readLine();
               }
               }
              catch(Exception e){
               return e.toString();
              }   
          }    
  
      }).start();
  
      return total;
  
  
  
  }
  </code></pre>
  
  <p>When i call the method it returns null.</p>
  
  <pre><code> Rate_fetch rf=new Rate_fetch();
        String amt= rf.rate(prodList);
  </code></pre>