Package com.azure.core.util
Class SharedExecutorService
java.lang.Object
com.azure.core.util.SharedExecutorService
- All Implemented Interfaces:
Executor,ExecutorService
An
ExecutorService that is shared by multiple consumers.
The shared executor service is created using the following configuration settings:
azure.sdk.shared.threadpool.maxpoolsizesystem property orAZURE_SDK_SHARED_THREADPOOL_MAXPOOLSIZEenvironment variable - The maximum pool size of the shared executor service. If not set, it defaults to 10 times the number of available processors.azure.sdk.shared.threadpool.keepalivemillissystem property or {code AZURE_SDK_SHARED_THREADPOOL_KEEPALIVEMILLIS} environment variable - The keep alive time in millis for threads in the shared executor service. If not set, it defaults to 60 seconds. Limited to integer size.azure.sdk.shared.threadpool.usevirtualthreadssystem property orAZURE_SDK_SHARED_THREADPOOL_USEVIRTUALTHREADSenvironment variable - A boolean flag to indicate if the shared executor service should use virtual threads. If not set, it defaults to true. Ignored if virtual threads are not available in the runtime.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) Shutdown isn't supported for this executor service as it is shared by multiple consumers.voidstatic SharedExecutorServiceGets the shared instance of the executor service.invokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> TinvokeAny(Collection<? extends Callable<T>> tasks) <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) booleanChecks if the executor service is shutdown.booleanChecks if the executor service is terminated.voidshutdown()Shutdown isn't supported for this executor service as it is shared by multiple consumers.Shutdown isn't supported for this executor service as it is shared by multiple consumers.Future<?><T> Future<T><T> Future<T>
-
Method Details
-
getInstance
Gets the shared instance of the executor service.- Returns:
- The shared instance of the executor service.
-
shutdown
public void shutdown()Shutdown isn't supported for this executor service as it is shared by multiple consumers.Calling this method will result in an
UnsupportedOperationExceptionbeing thrown.- Specified by:
shutdownin interfaceExecutorService- Throws:
UnsupportedOperationException- This method will always throw an exception.
-
shutdownNow
Shutdown isn't supported for this executor service as it is shared by multiple consumers.Calling this method will result in an
UnsupportedOperationExceptionbeing thrown.- Specified by:
shutdownNowin interfaceExecutorService- Returns:
- Nothing will be returned as an exception will always be thrown.
- Throws:
UnsupportedOperationException- This method will always throw an exception.
-
isShutdown
public boolean isShutdown()Checks if the executor service is shutdown.Will always return false as the shared executor service cannot be shut down.
- Specified by:
isShutdownin interfaceExecutorService- Returns:
- False, as the shared executor service cannot be shut down.
-
isTerminated
public boolean isTerminated()Checks if the executor service is terminated.Will always return false as the shared executor service cannot be terminated.
- Specified by:
isTerminatedin interfaceExecutorService- Returns:
- False, as the shared executor service cannot be terminated.
-
awaitTermination
Shutdown isn't supported for this executor service as it is shared by multiple consumers.Calling this method will result in an
UnsupportedOperationExceptionbeing thrown.- Specified by:
awaitTerminationin interfaceExecutorService- Parameters:
timeout- The amount of time to wait for the executor service to shutdown.unit- The unit of time for the timeout.- Returns:
- Nothing will be returned as an exception will always be thrown.
- Throws:
UnsupportedOperationException- This method will always throw an exception.
-
execute
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-