我需要从我的所有模块中删除servletContext
的会话,因此我创建了一个计时器并将getServlet
上下文作为参数传递给TimerConnector
的对象
我从会话列表中删除会话但我不知道如何将新列表设置为getSessionContext或如何从getServletContext
类中的TimerConnector
删除属性
public class TimerConnector {
static TimerConnector instance;
public static synchronized TimerConnector getInstance() throws Exception {
if (instance == null) {
instance = new TimerConnector();
}
return instance;
}
protected TimerConnector(){
getSessioContextForDestroy();
}
public TimerConnector() {
}
private TimerScheduler scheduler;
public void getSessioContextForDestroy() {
// if scheduler is not init, try first.
if (scheduler == null) {
scheduler = TimerScheduler.getInstance();
}
}
}
我的classScheuler:
public class TimerScheduler {
private final static Logger LOGGER = Logger.getLogger(DctmConnectorScheduler.class) ;
/** the sole instance */
private static TimerScheduler instance;
/**
* The sole function to get an instance of the class
*/
public static synchronized TimerScheduler getInstance() {
if (instance == null) {
instance = new TimerScheduler();
}
return instance;
}
/** the flag */
private boolean isSchedulerStarted;
/** the timer for the connection tester scheduler */
private Timer timer;
protected TimerScheduler() {
startScheduler();
}
private void startScheduler() {
if (isSchedulerStarted) {
return;
}
try {
// default values
int delay = 600000;
int period = 600000;
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//Do sameting.............
} // end run()
}, delay, period);
} catch (final Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
// trace in PROD
LOGGER.error("*** Scheduler started");
refreshDctmHashtables();
isSchedulerStarted = true;
}
}