I have a requirement where I am planning to run a background process. Once user logs in into application, I need to have two processes done. 1. authenticate user and go to homepage 2. Get some data and put it in session.
If I do both at same time its going to take 10 minutes to get to homepage. Instead I want second process to run in backgrou开发者_开发知识库nd while authentication is being processed.
I don't need data from second process in homepage. I need it in some other page which i could access from session.
Can someone put me in right direction?
Thanks
Create a class which extends Thread
or implements Runnable
and run it. You can learn at the Sun tutorial how to do it. Reference it in a session scoped managed bean so that you can access it from other pages.
That said, it sounds like as if you're hauling some database table entirely into Java's memory which lasts 10 minutes. I strongly recommend to not do so. This is very memory-inefficient and it may blow up whenever multiple users accesses your application concurrently. Add some search/filter/paging logic and just write code accordingly that it queries only the data of interest based on the current request. Google also doesn't query zillions of records to store it in the session and display only 10 of them in the current request. Don't let Java take over the role of the DB and also don't underestimate the powers of the DB. It's very fast when properly modeled and indexed.
精彩评论