Concurrent programming inside Java EE container

I have several Quartz scheduled tasks that work quite intensively in IO and easily break into several tasks.

Tasks are created and scheduled inside the tomcat web container thanks to Spring.

Is everything all right if I use the java.util.concurrent API in the Job class and inside the Java EE container?

Can I share logical processors with Tomcat, using the size of FixedThreadPool and allocating several cores (for example, two in this example)?

int numberOfCores = Runtime.getRuntime().availableProcessors(); final int poolSize = numberOfCores - 2 // Give away Two slots for TOMCAT final ExecutorService executorPool = Executors.newFixedThreadPool(poolSize); 
+4
source share
2 answers

Yes you can do it. But before you put your work inside tomcat. Pay attention to the following.

Do you have a web application in tomcat? if so, is your web application a high-activity, high-load portal?
If so, your thread jobs will take up valuable processing from the tomcat server.

Is a job running streaming jobs tightly coupled or requires tomcat?
If your work is really up to you. you better create a separate batch server and use it. You can look at spring-batch for implementation.

+1
source

Perhaps carefully.

Keep in mind that not a single thread (different from the original one - let it call the web application stream) can reliably interact with the container. In general, using threads in a Java EE environment is not recommended. This is not unheard of.

Tomcat Options:

  • Java EE has a WorkManager API . There is at least one implementation for tomcat . I can’t say how well this works. This article talks more about this .

  • Start your own topics. The model for managing things can be Swing Event Disp Loop Loop with SwingUtilities.invokeLater(Runnable) ; in your case, workflows transfer work to operation in a container back to a container-safe web application stream. In this thread, a processing cycle will be executed, waiting for the completion of work flows.

  • Run worker requests to the tomcat server: your web application now acts as a client (web service?). Such a model will scale well to disable operation, as suggested by AkhilDev, to other servers.

+1
source

All Articles