Hi.
The beaty of modularity
I have a very simple servlet that acts as a controller (main controller).Upon
receiving a request, it decides what handler object to use (sub-controllers) and
forwards it the request.The handler handles the request and prepares the
response.Pretty straightforward.
Now i need to have a mechanism for checking the validity of the session,time
outs,illegal accesses etc.So i ve made a filter, a session validator, that does just
that, so the request passes from the validator filter before reaching the main
controller.
In this filter, for best modularity, i create a sessionManager object which provides
all the functions i need for validation.Each time a request arrives,a new
sessionManager(request.getSession()) object is created inside doFilter, and it's
validator methods are invoked.However, creating a new sessionManager each time a
request arrives is bad to efficiency.
So, recalling that a filter's init method is called only once, i can create ONE
sessionManager instance there, and use it's methods in every thread of the doFilter
method.Therefore all validating methods of the sessionManager must take at least the
session object as an argument.
some fragments of codes:
public class validatorFilter...
public void init(){
....
sessionManager sm = new sessionManager();
....
}
public void doFilter(...)...{
...
boolean b = sm.isTimedOut(request.getSession());
...
}
Do i have to consider about multithreading?
Is there a possibility that while istimedOut is checking session1, another call to the
same function (but on session2) could affect in any way the first call?
Do i have to make all validating functions synchronized?
If i make all these functions static (tempting!), won't there be conflicts?
Thanks for your time.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html