how to wait for active servlets before ending session?

M

Mohun Biswas

My webapp has a Login servlet which creates a Session object, after
which any number of other connections may take place in parallel within
that session. The session is ended by a Logout servlet which calls
Session.invalidate().

The problem is that the client is not a traditional browser but rather a
dedicated, custom-built program which may fork multiple copies of itself
in order to take advantage of Java threading on the server side. Thus
when the Logout servlet is invoked, a few other servlets may still be
active. Needless to say, if the session is invalidated while these are
still working things go haywire. I need a way for Logout to wait till
it's the only active servlet before ending the session. Any ideas?

J2SE 1.4.2, Servlet API 2.4

Thanks,
M.B.
 
W

William Brogden

My webapp has a Login servlet which creates a Session object, after
which any number of other connections may take place in parallel within
that session. The session is ended by a Logout servlet which calls
Session.invalidate().

The problem is that the client is not a traditional browser but rather a
dedicated, custom-built program which may fork multiple copies of itself
in order to take advantage of Java threading on the server side. Thus
when the Logout servlet is invoked, a few other servlets may still be
active. Needless to say, if the session is invalidated while these are
still working things go haywire. I need a way for Logout to wait till
it's the only active servlet before ending the session. Any ideas?

Have your other Threads insert some marker object in the session.

Bill
 
M

Mohun Biswas

William said:
Have your other Threads insert some marker object in the session.

Not quite sure what you mean here - if you mean I should synchronize on
some common object, I could but it would effectively defeat threading
which I could do better by just implementing SingleThreadModel.

But maybe you mean I could store an Integer in the session and have each
servlet thread increment at entry and decrement at exit, and just
synchronize that Integer? That would work. Come to think of it, maybe I
could do something with the new EventListener interfaces , e.g.
HttpSessionBindingListener. I'll check it out, thanks.

M.B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top