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?