views:

35

answers:

1

Hi all,

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 background 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

+1  A: 

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.

BalusC
Thanks for the reply Balusc,My requirment is to populate child menu's on a page when user selects a value from parent dropdown without submit. Our engineer don't want page to refresh for every change on parent menu. I first thought of using javascript to do this by adding a hidden variable which is referenced to a map in managed bean. But now, that takes atleast 30 web service calls for each value in parent dropdown. So I planned to moving this webservice calls when application starts up and storing that in session. but I don't want user to wait for 10 minutes to get into home page.
Mahi
So I want this to be done in background while user can still browse my website. I googled for different ways to do it and went through this( http://www.coderanch.com/t/488860/JSF/java/best-way-do-background-processing ) which suggest we should not use Thread in Web application development which makes it unmanagable
Mahi
If it's not user-specific data, just store it in an application scoped managed bean which get loaded during webapp startup.
BalusC