为什么ThreadLocal 有时可能get()得到对象的值有时可以有时不行
package com.emetacenter.sysadmin;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class LogContext {
public static final int ACTION_LOGIN = 1;
public static final int ACTION_RESOURCE_ADD = 2;
public static final int ACTION_RESOURCE_MODIFY = 3;
public static final int ACTION_RESOURCE_PUBLISH = 4;
public static final int ACTION_RESOURCE_CHECKOUT = 5;
public static final int ACTION_RESOURCE_REMOVE = 6;
public static final int ACTION_RESOURCE_EXPORT = 7;
public LogContext() {
}
//线程共享变量
//根据线程保存日志信息,每一线程保存各自的日志信息,不同线程中的日志信息除会话ID外可能相同。
private static final ThreadLocal _log = new ThreadLocal();
public static void setLog(Log log) {
_log.set(log);
}
//提取参数集合对象
public static Log getLog() {
Log log = new Log();
if (_log.get() != null) {
Log _l = (Log) _log.get();
log.setUserID(_l.getUserID());
log.setUserName(_l.getUserName());
log.setIpAddress(_l.getIpAddress());
}
return log;
}
}
我在 登陆Servlet中已经set进对象的了
Log log = new Log();
log.setUserID(userID);
log.setUserName(user.getUserName());
log.setIpAddress(request.getRemoteAddr());
LogContext.setLog(log);
请大家帮忙兄弟解决急用啊