I made an jsf application.This application has a menu containing start,stop buttons.When start is pressed , application starts to get data from web sites, and updates its database.The application also has progress bar for update process.However,this process takes a long time to finish.I want that when i close my browser , it should go on updating database.Besides, when i open it again, i should get previous state.However, this isn’t happening.When i close browser the application closes too.How do i do that?
Thanks.
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
@ApplicationScopedbean 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):
@ApplicationScopedmanaged bean that will contain and handle the tasks.ExecutorServiceor similar technologies. Note: don’t dare to manually start new threads by your own, this will only lead to kill your web application server.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.