On Tue, 20 Jul 1999, Timothy Lim wrote:

} You can have a boolean(or int, if you want a counting
} semaphore) that is set when the servlet is in use.

} > 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?

I don't belive that a simple boolean will work in this case.  You'll need
to know which user is the "right" one at all times.  A boolean simply
allows for strict single-threaded running.

You probably want something like this:  (a) a class variable (not an
instance variable) that has the active user's session ID, (b) proper
synchronization on the code that sets and unsets the active session tag,
and (c) some thread that logs out the active user after some timeout.

(a) is necessary to share the token among all instances of the servlet,
since multiple requests may not go to the same instance.

(b) is necessary since you might introduce a race condition setting the
value and you might display a "OK" screen when another instance came along
and took the authentication away in the middle.

(c) is also necessary since you can't tell when a user has closed their
browser.  So, if someone forgets to log out, and closes their browser,
then you're quite stuck.  The session token won't be remembered by the
browser, so the same user might be locked out.  You could store user ID's
instead of session ID's, but that doesn't necessary guarantee only one
user at a time.


Jim

___________________________________________________________________________
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