Xizhen,

> Is it possible to disallow multiple users logging in and running Java
> Servlets at the same time? I want to disallow access to my Java Servlets
> if another user has already logged on. Can I use session tracking to
> prevent this from happening - ie force other users to wait and log in
> again once the first user has logged out/closed his browser?

     Depends on how involved the servlet is, I guess.  I'll take a
quick shot at answering your question below, but it'd probably be more
useful if you explained why you want to do this, and what you're
trying to accomplish.

     You could just put all of the interesting stuff off in another
method and declare that method with the synchronized keyword, so
subsequent servlet requests will hang until the current request exits
the synchronized method.

     Or you could just have an instance boolean named "available".
The first few lines of the service method check the available variable
and then if false, returns a page saying "please try again in a few
seconds".  If true, sets the variable to false and gets on with doing
whatever it is the servlet does, the sets the variable to false.
You'd probably need to make the first few lines of the servelet
synchronized (from the start up until it sets the variable to false).
That way only one servlet at a time can check and set the available
variable to false.

     There's also a single-thread-mode (or is that model? :-) if the
issue is contention for servlet instance variables.  That's generally
not recommended because of the load factor.

Steven J. Owens
[EMAIL PROTECTED]
[EMAIL PROTECTED]

___________________________________________________________________________
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

Reply via email to