I’d like to define a background task that starts when my Cuba Application Server startups, like a Scheduled Task, but it never stops. The code is not related to any UI Screen and is used for
creating some backend business logic to acquire data from a real-time source (like an external broker) and store it into the DBMS.
What’s the best way to manage such a task in CUBA Platform?
Declare a task executor (or task scheduler for periodic background activity) in spring.xml in the core module.
If you need one never-ending process than use just one thread:
Inject this executor to one of application beans in the core module and call myExecutor.execute(Runnable) to start background task.
CUBA requires user code to be authenticated, e.g. when you are persisting entities to DB or using DataManager or UserSessionSource.
Use com.haulmont.cuba.security.app.Authentication bean to authenticate your code as some system user.