nge*_*esh 3 java multithreading android
public int getChildrenCount(int groupPosition) {
if(children == null){
new SalesRequest().execute(); // runs in other thread which
// initialises children with some value.
while(children == null){
// I'm doin this to avoid null pointer Exception.
// So it comes out of the loop only when childern
// gets initialised.
}
}
return children.length;
}
Run Code Online (Sandbox Code Playgroud)
但我对我处理这个问题的方式并不满意.有一个更好的方法吗?
您可以使用CountDownLatch等待其他线程完成.
http://download.oracle.com/javase/1,5.0/docs/api/java/util/concurrent/CountDownLatch.html
| 归档时间: |
|
| 查看次数: |
2066 次 |
| 最近记录: |