Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session timeout

 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Vijay




and
 
Natarajan Shankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shankar,

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

 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Giri Kosuru
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay,

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.

Giri.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic