我的需求就是在android 中,需要异步上传一批图片检测,但是结果要按顺序加入list中,相当于调用方法有序,但回调无序,如何解决?
下面是模拟代码,如何实现在新建线程的情况下保证list.add方法正常,按序执行
public class Test {
public static void main(String args[]) {
for (int i = 0; i < 10; ++i) {
test1(i);
}
}
static List<String> arrayList = new ArrayList<>();
private static void test1(final int i) {
new Thread(new Runnable() {
@Override
public void run() {
try {
arrayList.add(i, i + "position");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
慕桂英3389331
胡子哥哥
守候你守候我
缥缈止盈
相关分类