Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling number of Threads for ManagedExecutorServices / Java EE 7

In Java SE one can use constructs like

ExecutorService es1 = Executors.newSingleThreadExecutor();
ExecutorService es2 = Executors.newFixedThreadPool(10);

to control the number of threads available to the executor service. In Java EE 7 it's possible to inject executor services:

@Resource 
private ManagedExecutorService mes;

But how can I control the number of threads available to the managed executor service ? For example, in the application I'm writing, there is an executor service that has to be executed in a single thread. So I can't just let the platform choose its preferred number of threads.

like image 232
user120513 Avatar asked Nov 01 '22 06:11

user120513


1 Answers

Actually, this setting should be set in the server settings, through admin console (in GlassFish for example), or during the creation of the service:

asadmin create-managed-executor-service --corepoolsize=10 --maximumpoolsize=20 concurrent/mes
  • See Create ManagedExecutorService, ManagedScheduledExecutorService, ManagedThreadFactory, ContextService in GlassFish 4.
like image 190
Eng.Fouad Avatar answered Nov 13 '22 16:11

Eng.Fouad