In my Jakarta/Java EE (Tomcat) project I need to connect to a Serial device and communicate with it. To achieve this, I have to open the connection on server startup. From this point on, I can run part of the program (like different thread) continuously for communication purpose. This part of the program should therefore run independently of user requests, but it has to be able to access the communication part.
As a possible solution I have read that I could use the default main method, but in my case, it does not get executed.
[I can’t use two separate programs (one SE and one EE) because I need to access the variables/Objects.]
So, how to safely execute a function that can run continuously on server startup? (Please provide an example)