Is there a reason to prefer doing this:
private static ExecutorService service = Executors.newScheduledThreadPool(10);
over this:
private static ExecutorService service = new ScheduledThreadPoolExecutor(10);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no particular reason, no. The
Executorsstatic methods are there for convenience and were written to cover a large percentage of the standard use cases.Although not in the case you mention, usage of some of the other static methods make your code vastly simpler and more readable. For example:
Versus:
The only possible reason I can think of why using the
Executorsmethods could be better is if in future JDK versions, they changed the defaults for some of the underlyingExecutorServiceclasses and the static methods would then be adjusted by Sun/Oracle to make better use of the new constructor arguments and you wouldn’t have to change your code.