Having trouble finding a solution for my situation here. Sorry if this has been answered before but I couldn’t find one that worked for me.
Problem: Trying to test if a user session has been active for longer than the timeout limit.
I am trying to use the session start time and the current system time and subtract them and if the result is greater than the timeout var – kill the session.
So:
for (LogSession logSession : sessionLogList) {
Calendar sessionStartTime = logSession.getStartTime();
Calendar currentSysTime = Calendar.getInstance();
currentSysTime.setTime(currentSysTime.getTime());
Calendar activeTime = Calendar.getInstance();
activeTime.setTime(sessionStartTime.getTime());
activeTime.add(activeTime.getTime(), - currentSysTime.getTime());
if ( activeTime.getTime() > timeoutLimit) {
// Do something
}
}
I am obviously getting an error message on the activeTime.add line but am unsure of the needed approach here. Any help would be great thanks.
Timeout is currently set to 15 minutes but is a global variable that can be changed.
Your sample seems to have a few errors in it but here is how I would go about it.