スレッドスレッドでいくつかのメソッドを実行した後、実行が成功したかどうかを判断する必要があります。
public void run(){}
run()メソッドの返品値は空ですが、どうすればよいですか?
解決:
コード:
パッケージcom.example.thread; import java.io.ioexception; import java.io.inputStream; Import java.net.httpurlconnection; Import java.net.malformedexception; Import java.net.url; Import Java.util.current.call.call.-cloid.util.util.util.util.util.util com.example.streamtool.streamtool; public class mythread1を実装する<string> {private static final string tag = "xxxyyy";プライベート文字列電話;プライベート文字列名; public mythread1(文字列名、文字列電話){this.name = name; this.phone = phone; } // public mythread1(string name、string phone){// super(name); // this.phone = phone; //} // public void run(){// log.i(tag、thread.currentthread()。 "http://www.dianping.com/ajax/json/account/reg/mobile/send?m=" + phone + "&flow = t&callback = dp._jsonprequest._5"; // stringbuilder strbui = new Stringbuilder(newpath); url(strbui.tostring()); // httpurlconnection con =(httpurlconnection)url.openconnection(); // con.addrequestproperty( "content-type"、 "text/html; charset = utf-8"); 「Mozilla/5.0(Windows NT 6.1)AppleWebkit/537.36(Khtml、geckoのように)Chrome/38.0.2125.104 Safari/537.36 "); // Con.AddrequestProperty(" Cookie "、 "_hc.v =/" /// "0ffcdf91-a4d6-4b08-8800-3d59d2e2fe45.1413899372 /// __UTMA = 1.29319792.1412090870.141360969696969696969696609660960; _tr.u = 7dhy065f = 17; 13.T = 17Deda7D2A7D8E46D84BF12A74627B72; _HC.V =/"///" 1BDAD871-405E-46E3-97D6-46571AD48E14.1413897928 //// "/"; JSESSIONID = 891671FC6B450418DD6E0611A3E4CF48 "); (con.getResponseCode()== 200){// inputstream inputstr = con.getInputStream(); // string info = new String(inputtstr.Read(input-8 "); // log.i(tag、thread.currentthread()。自動生成キャッチブロック// e.printstacktrace(); //} catch(ioexception e){// // // todo auto-fenerated catch block // e.printstacktrace(); //} catch(ioexception e){// // todo auto-generated catch block // e.printstacktrace TODO自動生成キャッチブロック// e.printstacktrace(); //} // //} @Override public String Call()throws exception {log.i(tag、thread.currentthread()。getName() + "...... start"); string newpath = "http://www.dianping.com/ajax/json/account/reg/mobile/send?m=" + phone + "&flow = t&callback = dp._jsonprequest._5"; stringbuilder strbui = new StringBuilder(NewPath); try {url url = new url(strbui.tostring()); httpurlconnection con =(httpurlconnection)url.openconnection(); con.addrequestproperty( "content-type"、 "text/html; charset = utf-8"); con.addrequestproperty( "user-agent"、 "mozilla/5.0(windows nt 6.1)applewebkit/537.36(khtml、geckoのような)chrome/38.0.2125.104 safari/537.36"); con.addrequestproperty( "cookie"、 "_hc.v =/" /// "0ffcdf91-a4d6-4b08-8800-3d59d2e2fe45.1413899372 ////"/"; abtest =/"48,124 // | 52,133 // | 47,122 // | 44,106 // | 45,115/"; __UTMZ = 1.1413645970.5.2.T.DIANPING.COM | UTMCMD = UTMCCT =/XIAN; T_RCT = 2172824 | 2171729 | 6457678; 13.TS = CD3BD6495620E2A204912C4BDFD43220; _HC.V =/"//" 1BDAD871-405E-46E3-97D6-46571AD48E14.1413897928 //// "/"; JSESSIONID = 891671FC6B450418DD6E0611A3E4CF48 "); con.addrequestproperty( "referer"、 "http://t.dianping.com/register"); con.setConnectTimeout(5000); con.setRequestMethod( "get");フロートx = 3.4f; if(con.getResponseCode()== 200){inputstream inputstr = con.getInputStream(); string info = new String(streamtool.read(inputstr)、 "utf-8"); log.i(tag、thread.currentthread()。getname() + info); if(info.contains( "200")) "200"を返します。 }} catch(malformedurlexception e){// dodo auto-enerated catch block e.printstacktrace(); } catch(ioException e){// todo auto-fenated catch block e.printstacktrace(); } catch(例外e){// todo auto-enerated catch block e.printstacktrace(); } // TODO自動生成方法スタブリターン "404"; }}返品値を処理します
executorservice exec = executors.newcachedthreadpool(); arrayList <future <string >> results = new ArrayList <Future <String >>(); for(int i = 0; i <num; i ++)results.add(exec.submit(selectthread(telnumber))); for(future <string> fs:results)try {if(fs.get()。equals( "200"))success ++; } catch(arturnedexception e){// todo auto-fenated catch block e.printstacktrace(); } catch(executionException e){// todo auto-fenated catch block e.printstacktrace(); }成功を返す;上記はこの記事に関するものです。すべての人の学習に役立つことを願っています。