File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Session timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session timeout" Watch "Session timeout" New topic

Session timeout

Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243

I have the following situation.

In my application, there are 4 to 5 beans in session scope. These beans
will be created at different periods of time.

The business rule is, if a bean is not accessed for more than a period of time
(say 10min), that bean should be reset to default values. This rule applies
to only a couple of beans...not all.....

Now, i feel i cannot set session timeout for this..bcos i fear i may loose all the beans.....

Is my understanding is correct???

Help pls.....TIA


Natarajan Shankar
Ranch Hand

Joined: Jun 10, 2004
Posts: 53
Hello Vijay,
Hope your business rules need to set session time out for each bean i.e, Bean based. But the "Session time out" we're speaking is application based. So as per m understandin you cannot do this.

Best Regards<br />N.Shankar<br />SCJP, SCWCD
Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
Hi Shankar,

Is there any other work around for this kind of situation???

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Looks like you will need to use a Thread that wakes up after a certain no of seconds/minutes and checks if the bean has been accessed and takes the required action.

So, you can have a variable in the bean that records the time it is accessed, and when the thread wakes up it checks the value of that variable, if the difference from the current time is more than the 'timeout' value, it resets it.

But you might want to see if there is another way of enforcing that business requirements using some built-in session/request/application feature. Creating your own threads can get messy if you are not totally comfortable with multi-threading concepts, and if you do decide to use it, you will need to decide whether to run that a thread for the app or each session or each bean etc..

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Giri Kosuru

Joined: Nov 13, 2001
Posts: 5

I have a theoritical solution. You can add a HttpSessionAttributeListener and in the "attributeAdded" method, check the name of the attribute added(In your case probably each bean) and when added put this time in session as a variable.

In each JSP of your page or in super class of that JSP (if you have one) include a small jsp file (include file) which checks for the time differences from the time each bean inserted in the session to the present request time(System.getTimeInMillis() I guess) and based on that you can do what ever you want.

I agree. Here's the link:
subject: Session timeout
It's not a secret anymore!