Skip to content

Commit

Permalink
add socket taskrunner
Browse files Browse the repository at this point in the history
  • Loading branch information
leelance committed Aug 19, 2016
1 parent f5077bf commit af82bf5
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lance.websocket.config;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;

import org.apache.commons.lang3.time.DateUtils;

public class SockTaskRunner implements Runnable{
public void run() {
Iterator<SocketSessionInfo> it = SocketSessionHandler.sessions.iterator();
while(it.hasNext()) {
SocketSessionInfo info = it.next();

if(DateUtils.truncatedCompareTo(new Date(), info.getEndSessionTime(), Calendar.MINUTE) > 0) {
try {
info.getWebSocketSession().close();
SocketSessionHandler.newInstance().removeSession(info.getSessionId());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

0 comments on commit af82bf5

Please sign in to comment.