我有这个代码:
public class JsoupParser {
ArrayList<CompanyInfo> arr = new ArrayList<CompanyInfo>();
public JsoupParser() {}
public ArrayList<CompanyInfo> parse(final String link) throws IOException {
Runnable runnable = new Runnable() {
public void run() {
// Here I do some operations and then assign some value
// to my `arr` ArrayList
}
};
new Thread(runnable).start();
return arr; // error here, as expected
}
}
系统立即返回arr
,此时是null
。
我怎样才能arr
只有在Thread
完成后才能返回?我怎样才能知道,Thread
已经完成了?