3

The class javax.enterprise.concurrent.ManagedExecutorService manages threads within Enterprise Java Bean. As threads in EJBs should not be started in the classical Java SE way, I use the ManagedExecutorService to handle threads.

"Obligatory warning: Creating your own threads in a Java EE app server (even Tomcat) is discouraged as it can be a huge performance issue and in most cases will prevent container functionality, such as JNDI, from working. The new threads won't know which application they belong to, the Thread context classloader will not be set and many other hidden issues."

In Java SE you can define the maximum number of threads, as shown in the following code.

java.util.concurrent.Executors.newFixedThreadPool(numberOfThreadsInThePool);

Do you know how to limit the number of threads excecuted by the ManagedExecutorService?

Community
  • 1
  • 1

2 Answers2

0

When you are using an EE container, you should address issues about the number of threads through configuration of the container. For Glassfish, check the Oracle documentation on thread pool management and performance tuning.

Warren Dew
  • 8,790
  • 3
  • 30
  • 44
0

The maximum thread pool size can be determined when the ManagedExcecutorService is created in the Glassfish Application Server. According to the this article https://blogs.oracle.com/arungupta/entry/create_managedexecutorservice_managedscheduledexecutorservice_managedthreadfactory_contextservice glassfish's asadmin command has a parameter "maximumpoolsize" which defines the maximum number of threads used by the ManagedExcecutorService.

asadmin create-managed-executor-service concurrent/myExecutor --maximumpoolsize=20