Java ライブラリAsyncHttpClientのコード ブロックを見ると、クライアントは新しいスレッド (a Future
) を開始してリクエストを作成します。コールバックは同じスレッドで発生しますか、それとも「メイン」スレッド (この場合、new AsyncHttpClient()
呼び出されたスレッド?
import com.ning.http.client.*;
import java.util.concurrent.Future;
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
asyncHttpClient.prepareGet("http://www.ning.com/ ").execute(new AsyncCompletionHandler<Response>(){
@Override
public Response onCompleted(Response response) throws Exception{
// Do something with the Response
// ...
return response;
}
@Override
public void onThrowable(Throwable t){
// Something wrong happened.
}
});