How can you configure, in a portable way, the number of threads used by a ManagedExecutorService?
Click on the arrows to vote for the correct answer
A. B. C. D.A.
The correct answer is D. configuring the thread pool info in the deployment descriptor.
In Java EE 7, the ManagedExecutorService interface provides a standard way to execute tasks asynchronously in a Java EE container. ManagedExecutorService is designed to be portable across Java EE containers, allowing Java EE applications to be easily migrated between different Java EE product providers.
The ManagedExecutorService interface provides several methods for submitting tasks, such as execute(), submit(), and invokeAll(). However, it does not provide a way to configure the number of threads used by the executor service.
To configure the number of threads used by a ManagedExecutorService in a portable way, you can use the <managed-executor-service> element in the deployment descriptor (web.xml for web applications, ejb-jar.xml for EJB applications).
The <managed-executor-service> element allows you to specify the following properties:
For example, the following snippet shows how to configure a ManagedExecutorService with a maximum of 10 threads and a queue capacity of 100:
php<managed-executor-service> <core-pool-size>5</core-pool-size> <max-pool-size>10</max-pool-size> <keep-alive-seconds>60</keep-alive-seconds> <queue-capacity>100</queue-capacity> </managed-executor-service>
By configuring the ManagedExecutorService in the deployment descriptor, the application can be easily migrated to different Java EE product providers without requiring any code changes.
Option A is incorrect because although it is possible to programmatically configure a ManagedExecutorService, it is not a portable solution as it would depend on the specific implementation of the Java EE container.
Option B is incorrect because ManagedExecutors is not a standard utility class provided by the Java EE specification.
Option C is incorrect because it is not true. The Java EE specification defines a standard way to configure a ManagedExecutorService in a portable way through the deployment descriptor.