In my case, I would not extend the session life. Instead, create a task and add the object that performs the task into a Queue in an @ApplicationScoped
bean and save in database (or any other place) the user that started the job and the status of the job.
When the user logs off (manually logging off or closing the web browser), the task will still be executed because is managed by the whole application (not by a request nor user session). When the user logs in again, he/she could ask to this application queue about the status of the task.
You will need (at least):
- An
@ApplicationScoped
managed bean that will contain and handle the tasks.
- A way to handle and execute one or more tasks at the same time. This could be achieved with a
ExecutorService
or similar technologies. Note: don't dare to manually start new threads by your own, this will only lead to kill your web application server.
- An structure to map the user with the tasks he/she has started. It could be mapped with a
Map<String, List<Task>>
in order that a single user could have more than 1 task at the moment. It would be better to save this in a database (or similar) in order to have a log for these tasks that don't reside in memory. You can even design this in order that if you undeploy the web application or the server suddenly shut downs, you could restart the tasks at hand from a savestate point.