dinesh
(dinesh thalis)
November 4, 2010, 7:48am
1
My system has 2 logging users A & B. I log system using A user, now I want to logout user B when I click button how can I do it
I did it below way
private ApplicationContext ctx;
private WebApplicationContext webctx;
ctx = getMainForm().getContext();
webctx = (WebApplicationContext) ctx;
try {
webctx.getHttpSession().getSessionContext().getSession("007").invalidate();
} catch (Exception e) {
System.out.println(e);
}
need to inavalidate user 007 but that gave “java.lang.NullPointerException”
above code “getSessionContext()”, “getSession(”“)” Deprecated how can i solve this problem.
How to invalidate system all logging users ?
dinesh
(dinesh thalis)
November 5, 2010, 6:46am
2
I found answer for that problem Please correct if I wrong
1st I put userId & session into map
sessionMap.put(userId, session);
after that I remove users using button click
try {
if (MainForm.sessionMap.containsKey(arUsers[i]
) == true) {
MainForm.sessionMap.get(arUsers[i]
).invalidate();
MainForm.sessionMap.remove(arUsers[i]
);
}
} catch (Exception e) {
System.out.println(e);
}
Bobby
(Bobby Bissett)
November 5, 2010, 3:56pm
3
Looks like that ought to work, but make sure you’re careful about concurrency when dealing with that map. You could use a thread-safe map implementation, but since your method is a check-then-act sequence you’re better off using any map implementation and just don’t expose it to any other code. In your code, you should synchronize the put and invalidate/remove methods using the same lock.
Cheers,
Bobby