sdk-java icon indicating copy to clipboard operation
sdk-java copied to clipboard

Using executors incorrectly.

Open georgantasp opened this issue 7 years ago • 3 comments

The SDK's HttpUtility is needlessly creating threads for every request execution.

        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<ANetApiResponse> future = executor.submit(new HttpCallTask(env, request, classType));
        executor.shutdown(); // Important!
		
        try {
        	response = future.get();
        	logger.debug(String.format("Response: '%s'", response));
	} ...

This is creating a new thread for every execution. EXPENSIVE! I could be wrong, but I think it's a race condition where to assume the HTTPCallTask is started before the executor gets shutdown. Waiting on future.get() which means no call is ever asynchronous.

georgantasp avatar May 23 '17 16:05 georgantasp