Calling Application.close() from another thread

Hi,

I’m wanting to call Application.close() from another thread to effectively close users sessions and wanting to redirect them so they start a new session (The standard behaviour for Application.close())

But when I call it from another thread it just gives an out of sync error for the client.

Is there any way I can achieve this?

As a side note: I also get this issue if I have multiple tabs open and then call Application.close() from one of them. The initiating tab is fine, but other tabs get an out of sync error. I partially resolved it by issuing a window.executeJavascript(setTimeout(window.href= …)) and using IcePush addon. But it is somewhat unreliable as the call doesn’t usually make it to the client before the Application.close() call has cut off communications.

It sounds like, effectively, you’d like to be able to log out users. For instance, an admin user could get a list of current sessions and log them out. The problem is that you’re changing things on the server side for a user so that they don’t match the client side and the user gets the ‘out of sync’ error. Am I understanding correctly?

One simple solution would be to set some flag in a user’s Application object that is checked at each request. You could add a simple volatile boolean field or AtomicBoolean object with a setter to the Application object. To check it at each request implement
HttpServletRequestListener
and check the field during onRequestStart(). I’m not sure you can close the application at that point (I ran into trouble there manually expiring sessions), but it might be worth a try.

Cheers,
Bobby

Thanks, that sounds like a good way to go about it.