0
나는 메서드가 있습니다. 이 메소드 내에서 Executors에 의해 태스크를 실행합니다. 그 작품은 서버에서 데이터를 가져와 Arraylist 결과를 채 웁니다. 결과를 작성 후countinue Executors.newFixedThreadPool의 작업 완료 후 메서드
public Paginator(String secSrv, int total, ExecutorService executorService, Cookie cookie) {
securitySrv = secSrv;
totalItems = total;
this.executorService = executorService;
this.cookie = cookie;
}
ArrayList<Suser> results = new ArrayList<>();
public ArrayList<Suser> generatePage(int currentPage) {
fetchAllUsers(currentPage);
......
for (int i = startItem; i < startItem + numOfData; i++) {
pageData.add(results.get(i-1));
}
은 ExecutorService를가 작업을 완료하고 난 다시 내 방법을 계속 할 수있는 나는 내가 아는 coud을이 arraylist.how을 사용해야 ArrayList를?
private void fetchAllUsers(final int currentPage) {
Runnable fetchUserListFromSrv = new Runnable() {
@Override
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
JSONObject count = new JSONObject();
try {
count.put("count", 10);
count.put("page", currentPage);
String SearchUsersPagingResult = ...
results.addAll(susers) ;
} catch (JSONException e) {
e.printStackTrace();
}
}
};
executorService.submit(fetchUserListFromSrv);
}
친구 나는이 내 코드를 변경하고 모든 ok.http입니다 : //codepad.org/C9swPyU5. 당신은 나에게 설명 할 수 있겠는가,이 방법은 주 스레드를 잡고 그 작업을 마친 후 주 스레드를 다시 시작 하는가? – Groot
Future는 비동기 계산의 결과를 나타냅니다. Callable 인터페이스는, 다른 thread에 의해 인스턴스가 실행될 가능성이있는 클래스 용으로 설계된 Runnable와 유사합니다. 그래서, 귀하의 질문에 대한 대답은 아니오, 방법 fetchAllUsers() 메인 스레드를 차단하지 않습니다. –
하지만, 왜 내 스레드가 작업을 마칠 때까지 메인 메소드'generatePage (int currentPage)'에 다른 코드가 실행되지 않습니까? main 메소드에이 코드가 실행되면 오류가 발생합니까? – Groot