RequestHolder工具类

package com.inspire.ssm.common;

import com.inspire.ssm.model.SysUser;

import javax.servlet.http.HttpServletRequest;

public class RequestHolder {

    /**
* 处理高并发的对象
* 1. 每个线程是独立的
* 2. 登陆的时候会把每个用户的信息和请求的信息放入线程里面
* 3. 而在以后取用户信息可以直接取这里取
*/
private static final ThreadLocal<SysUser> userHolder = new ThreadLocal<SysUser>(); private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>(); public static void add(SysUser sysUser) {
userHolder.set(sysUser);
} public static void add(HttpServletRequest request) {
requestHolder.set(request);
} public static SysUser getCurrentUser() {
return userHolder.get();
} public static HttpServletRequest getCurrentRequest() {
return requestHolder.get();
} public static void remove() {
userHolder.remove();
requestHolder.remove();
}
}
上一篇:(一)机器视觉简介


下一篇:[论文笔记]PersonNet: Person Re-identification with Deep Convolutional Neural Networks