Spring中构造器、init-method、@PostConstruct、afterPropertiesSet孰先孰后,自动注入发生时间以及单例多例的区别、SSH线程安全问题

发布时间 2023-09-26 17:21:31作者: 小小鸟儿!

 

引用: https://www.cnblogs.com/qlqwjy/p/9417034.html

  首先明白,spring的IOC功能需要是利用反射原理,反射获取类的无参构造方法创建对象,如果一个类没有无参的构造方法spring是不会创建对象的。在这里需要提醒一下,如果我们在class中没有显示的声明构造方法,默认会生成一个无参构造方法,但是当我们显示的声明一个有参构造方法的时候,JVM不会帮我们生成无参构造方法,所以我们声明一个带参数的构造方法也需要声明一个无参构造方法。(题外话:如果父类声明一个有参构造方法,子类需要在构造方法第一行显示的调用父类构造方法,因为子类的对象也是父类的对象,所以在创建子类对象的同时也会创建父类的对象,如果父类有默认的无参构造函数,JVM会调用无参构造函数,但是有了有参的就需要我们在子类的构造函数中调用父类的有参构造函数)

 

 1.Person类只有一个有参构造方法,报错如下:

No default constructor found; nested exception is java.lang.NoSuchMethodException: zd.dms.job.ebuy.Person.<init>()

2.大体知道有三种生命周期回调方法去参与到spring的生命周期,查阅了一下如下:(创建和销毁的执行顺序也是下面顺序)

  • 在指定方法上加上@PostConstruct 或@PreDestroy注解来制定该方法是在初始化之后还是销毁之前调用。
  • 通过实现 InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法;     
  • 通过 <bean> 元素的 init-method/destroy-method属性指定初始化之后 /销毁之前调用的操作方法;  

3.测试spring的顺序与注入的顺序与单例多例的问题

1.Person.java

复制代码
package zd.dms.job.ebuy;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import zd.dms.dao.ebuy.GroupDao;

public class Person implements InitializingBean,DisposableBean{
    private String name;
    
    @Autowired
    private GroupDao groupDao;

    public Person() {
        System.out.println("---------------实例化一个Person对象----------");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }

    public void init() {
        System.out.println("------------这是xml的init方法----------....");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }

    public void destory() {
        System.out.println("---------------这是xml的destroy方法....");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }
    
    @PostConstruct
    public void init2() {
        System.out.println("------------这是@PostConstruct的init方法----------....");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }
    
    @PreDestroy
    public void destory2() {
        System.out.println("---------------这是@PreDestroy的destroy方法....");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("-----------这是DisposableBean的destroy方法....");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("-------这是InitializingBean的afterPropertiesSet方法....");
        System.out.println("---------------groupDao is -----------"+groupDao);
    }
}
复制代码

 

 -----------------------单例模式的xml配置以及结果---------------------------------------:

配置:

    <bean id="person" class="zd.dms.job.ebuy.Person" autowire="byType" destroy-method="destory" init-method="init"></bean> 

 

测试:将Person类注入到Action我们访问Action

复制代码
@Namespace("/qlqTest")
@SuppressWarnings("all")
public class TestAction extends DMSActionSupport {

    @Autowired
    private Person person;
    /**
     * 
     */
    private static final long serialVersionUID = -8934360924125349297L;

    @Autowired
    private GroupAndUserService groupAndUserService;

    private Map resultMap;

    @Action("test")
    public String testAction() {
        person.getClass();
        return "js";
    }
}
复制代码

 

当我们第一次访问该Action会创建Person对象,打印结果如下:

复制代码
- ---------------实例化一个Person对象----------
---------------groupDao is -----------null
------------这是@PostConstruct的init方法----------....
---------------groupDao is -----------zd.dms.dao.ebuy.GroupDaoImpl@435598e3
-------这是InitializingBean的afterPropertiesSet方法....
---------------groupDao is -----------zd.dms.dao.ebuy.GroupDaoImpl@435598e3
------------这是xml的init方法----------....
---------------groupDao is -----------zd.dms.dao.ebuy.GroupDaoImpl@435598e3
复制代码

 

证明对象创建的顺序:

    构造器-->自动注入-->@PostConstrut-->InitializingBean-->xml中配置init方法    

 

再次调用不会打印,证明默认是单例的  singleton,也就是无论我们访问多少次Action,Spring容器中只有一个这个Person实例对象。

 

销毁的时候的结果:

复制代码
---------------这是@PreDestroy的destroy方法....
---------------groupDao is -----------zd.dms.dao.ebuy.GroupDaoImpl@435598e3
-----------这是DisposableBean的destroy方法....
---------------groupDao is -----------zd.dms.dao.ebuy.GroupDaoImpl@435598e3
---------------这是xml的destroy方法....
---------------groupDao is -----------zd.dms.dao.ebuy.GroupDaoImpl@435598e3
复制代码

 

所以销毁顺序为:

  @PreDestroy--DisposableBean-->xml中destroy-method方法

 

 -----------------------多例模式的xml配置以及结果---------------------------------------:

配置:

<bean id="person" class="zd.dms.job.ebuy.Person" autowire="byType" destroy-method="destory" init-method="init" scope="prototype"></bean>

 

我们多次访问Action,所以Action会多次调用Person对象,发现会多次创建Person对象,也就是请求一次会创建一个对象,也就是多例:

 

 

 至于到底是该使用单例还是多例,这就需要我们平时的业务需求了,springMvc就是单例的,struts2默认就是多例的。我们也可以使用注解配置单例和多例,如下:

 

 

 

---------------------为了理解上面的单例多例的例子,继续测试---------------------

1.单例多例的对象创建问题

1.测试 action-service-dao是多-单-单 模式

Action:

复制代码
package cn.qlq.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

import cn.qlq.service.UserService;

@Namespace("/")
@ParentPackage("default")
@Controller("firstAction")
@Results({ @Result(name = "redirect", location = "/index2.jsp", type = "redirect"),
        @Result(name = "forward", location = "/index.jsp"),
        @Result(name = "json", type = "json", params = { "root", "responseMap" }) })
public class UserAction extends ActionSupport {

    private Map<String, Object> responseMap = new HashMap<String, Object>();

    @Autowired
    private UserService userService;

    public UserAction() {
        System.out.println("-----call UserAction 无参构造方法");
    }

    @Action("saveUser")
    public String saveUser() {
        userService.saveUser();
        return "json";
    }

    public Map<String, Object> getResponseMap() {
        return responseMap;
    }

    public void setResponseMap(Map<String, Object> responseMap) {
        this.responseMap = responseMap;
    }

}
复制代码

 

Service:

package cn.qlq.service;

public interface UserService {
    public void saveUser();
}
复制代码
package cn.qlq.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.qlq.dao.UserDao;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    public UserServiceImpl() {
        System.out.println("----- call UserServiceImpl 无参构造方法");
    }

    @Override
    public void saveUser() {
        userDao.saveUser();
    }

}
复制代码

 

Dao:

复制代码
package cn.qlq.dao;

public interface UserDao {

    public void saveUser();
}
复制代码
复制代码
package cn.qlq.dao;

import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {

    public UserDaoImpl() {
        System.out.println("-----call   UserDaoImpl 无参构造");
    }

    @Override
    public void saveUser() {
        try {
            Thread.sleep(4 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("----user dao (save user)---");
    }

}
复制代码

启动服务,查看控制台:(证明容器启动创建对象)

 

多次访问Action查看控制台:

 总结:

Action是struts默认多例:(注入Person类对象)

service层,默认是单例(注入GroupDaoImpl对象)

dao层默认也是单例,所以我们在多次访问的时候容器只创建Action层对象,并将Service与dao存在的对象注入进去。也就是容器有多个Action对象,但是只有一个Service、一个Dao对象。

 也就是我们上面的配置从Action到service到dao的作用域是多-单-单,:

 

2.测试 action-service-dao是多-单-多 模式

修改DaoImpl配置:

 

 多次访问Action查看控制台:

 总结:对于多-单-多的模式依旧是容器有多个Acction,一个service,一个dao对象。因为容器在创建action的时候在容器中可以找到service对象、且service是单例对象,所以不会创建service对象,也就不会创建dao对象。

 

3.测试 action-service-dao是多-多-多 模式

 将service也修改为多例:

 多次访问Action查看控制台:

总结:对于多-多-多 模式,每次创建Action之后由于要注入service对象,service也是多例,所以会创建service对象,创建service注入dao对象,dao对象也是多例,所以会创建dao对象。也就是每个请求action到dao都会创建新对象。

 

4.测试 action-service-dao是多-多-单 模式

 重新将dao设为单例:

 

 多次访问Action:

 

 总结:

  对于多-多-单 模式,每次创建Action之后由于要注入service对象,service也是多例,所以会创建service对象,创建service注入dao对象,dao对象是单例,所以不会创建dao对象。也就是每个请求action予service都会创建新对象,dao不会创建新对象。

 

 2.测试单例多例的线程安全问题(dao与service层单例存在线程安全问题)

 1.测试多-单-单模式

   Struts默认是多例,所以我们测试普通开发情况下的多-单-单的问题,假设dao有一成员变量,我们多个访问同时修改成员变量的值,查看结果:

dao的代码:

复制代码
package cn.qlq.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {
    private static Logger log = LoggerFactory.getLogger(UserDaoImpl.class);
    private int i = 1;

    public UserDaoImpl() {
        System.out.println("-----call   UserDaoImpl 无参构造");
    }

    @Override
    public void saveUser() {
        log.info("------threamName:{},value:{}", Thread.currentThread().getName(), String.valueOf(i++));
    }

}
复制代码

 

service是单例:

复制代码
package cn.qlq.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.qlq.dao.UserDao;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    public UserServiceImpl() {
        System.out.println("----- call UserServiceImpl 无参构造方法");
    }

    @Override
    public void saveUser() {
        userDao.saveUser();
    }

}
复制代码

 

Action还是上面代码。

 

测试代码:(模拟开启300个线程去访问Action)

复制代码
public class MyThread implements Runnable {

    @Override
    public void run() {
        HttpUtils.doGet("http://localhost/struts/saveUser.do");
    }

    public static void main(String[] args) {
        MyThread mt = new MyThread();
        for (int i = 0; i < 300; i++) {
            new Thread(mt).start();
        }
    }

}
复制代码

 

复制代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HttpUtils {

    private static Logger logger = LoggerFactory.getLogger(HttpUtils.class);

    /**
     * get请求
     * 
     * @return
     */
    public static String doGet(String url) {
        try {
            HttpClient client = new DefaultHttpClient();
            // 发送get请求
            HttpGet request = new HttpGet(url);

            HttpResponse response = client.execute(request);

            /** 请求发送成功,并得到响应 **/
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                /** 读取服务器返回过来的json字符串数据 **/
                String strResult = EntityUtils.toString(response.getEntity(), "utf-8");
                return strResult;
            }
        } catch (IOException e) {
            logger.debug("get data error");
        }

        return null;
    }

}
复制代码

 

日志采用slf4j配置:

复制代码
log4j.rootLogger=info,B

log4j.appender.A=org.apache.log4j.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n

log4j.appender.B=org.apache.log4j.RollingFileAppender
log4j.appender.B.File=E:\\test.log
log4j.appender.B.MaxFileSize=10MB
log4j.appender.B.MaxBackupIndex=5
log4j.appender.B.layout=org.apache.log4j.PatternLayout
log4j.appender.B.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
复制代码

 

查看访问之后的日志:

复制代码
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-90,value:1
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-275,value:2
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-94,value:3
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-174,value:4
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-221,value:5
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-294,value:6
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-123,value:7
2018-08-30 22:12:19 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-93,value:8
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-103,value:9
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-80,value:10
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-15,value:11
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-133,value:12
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-120,value:13
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-239,value:14
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-54,value:15
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-44,value:16
2018-08-30 22:12:20 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-264,value:17
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-51,value:18
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-272,value:19
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-139,value:20
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-143,value:21
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-69,value:22
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-26,value:23
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-178,value:24
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-171,value:25
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-203,value:26
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-118,value:27
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-238,value:28
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-24,value:29
2018-08-30 22:12:21 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-163,value:30
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-3,value:31
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-135,value:32
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-297,value:33
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-234,value:34
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-169,value:35
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-70,value:36
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-76,value:37
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-288,value:38
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-95,value:39
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-47,value:40
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-98,value:41
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-60,value:42
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-79,value:43
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-67,value:44
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-102,value:45
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-292,value:46
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-145,value:47
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-20,value:48
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-236,value:49
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-246,value:50
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-115,value:51
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-162,value:52
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-148,value:53
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-228,value:54
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-78,value:55
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-42,value:56
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-189,value:57
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-37,value:58
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-167,value:59
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-63,value:60
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-53,value:61
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-198,value:62
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-140,value:63
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-213,value:64
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-84,value:65
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-242,value:66
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-61,value:67
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-83,value:68
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-210,value:69
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-104,value:70
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-225,value:71
2018-08-30 22:12:22 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-277,value:72
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-91,value:73
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-188,value:74
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-50,value:75
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-81,value:76
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-132,value:77
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-48,value:78
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-149,value:79
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-197,value:80
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-278,value:81
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-124,value:82
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-146,value:83
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-32,value:84
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-159,value:85
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-122,value:86
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-269,value:87
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-243,value:88
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-17,value:89
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-55,value:90
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-202,value:91
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-191,value:92
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-71,value:93
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-2,value:94
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-256,value:95
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-68,value:96
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-181,value:97
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-18,value:98
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-46,value:99
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-14,value:100
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-258,value:101
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-96,value:102
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-157,value:103
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-116,value:104
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-180,value:105
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-223,value:106
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-199,value:107
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-266,value:108
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-153,value:109
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-142,value:110
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-241,value:111
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-137,value:112
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-113,value:113
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-154,value:114
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-271,value:115
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-301,value:116
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-279,value:117
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-166,value:118
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-77,value:119
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-127,value:120
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-22,value:121
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-286,value:122
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-298,value:123
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-224,value:124
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-240,value:125
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-151,value:126
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-43,value:127
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-293,value:128
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-270,value:129
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-284,value:130
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-164,value:131
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-274,value:132
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-73,value:133
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-62,value:134
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-105,value:135
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-7,value:136
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-82,value:137
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-200,value:138
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-41,value:139
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-25,value:140
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-27,value:141
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-150,value:142
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-192,value:143
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-35,value:144
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-19,value:145
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-134,value:146
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-211,value:147
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-173,value:148
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-260,value:149
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-111,value:150
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-112,value:151
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-117,value:152
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-49,value:153
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-282,value:154
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-16,value:155
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-254,value:156
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-12,value:157
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-209,value:158
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-119,value:159
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-108,value:160
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-208,value:161
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-250,value:162
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-175,value:163
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-29,value:164
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-235,value:165
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-212,value:166
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-176,value:167
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-92,value:168
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-170,value:169
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-283,value:170
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-64,value:171
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-226,value:172
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-215,value:173
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-185,value:174
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-100,value:175
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-30,value:176
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-85,value:177
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-45,value:178
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-110,value:179
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-155,value:180
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-187,value:181
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-299,value:182
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-156,value:183
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-33,value:184
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-52,value:185
2018-08-30 22:12:23 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-201,value:186
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-276,value:187
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-296,value:188
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-263,value:189
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-109,value:190
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-290,value:191
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-8,value:192
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-193,value:193
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-129,value:194
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-141,value:195
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-56,value:196
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-40,value:197
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-39,value:198
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-88,value:199
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-195,value:200
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-97,value:201
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-257,value:202
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-196,value:203
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-177,value:204
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-168,value:205
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-36,value:206
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-4,value:207
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-161,value:208
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-291,value:210
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-267,value:209
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-101,value:211
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-86,value:212
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-273,value:213
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-253,value:214
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-216,value:215
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-218,value:216
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-13,value:217
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-231,value:218
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-87,value:219
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-249,value:220
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-165,value:221
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-172,value:222
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-227,value:223
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-190,value:224
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-160,value:225
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-219,value:226
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-237,value:227
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-204,value:228
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-144,value:229
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-59,value:230
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-295,value:231
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-38,value:232
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-281,value:233
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-262,value:234
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-268,value:235
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-244,value:236
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-74,value:237
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-265,value:238
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-158,value:239
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-58,value:241
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-125,value:240
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-147,value:242
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-21,value:243
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-72,value:244
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-10,value:245
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-57,value:246
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-207,value:247
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-280,value:248
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-179,value:249
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-247,value:250
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-130,value:251
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-259,value:252
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-251,value:253
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-261,value:254
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-75,value:255
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-107,value:255
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-220,value:256
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-128,value:257
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-300,value:258
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-248,value:259
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-285,value:260
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-114,value:261
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-89,value:262
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-289,value:263
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-230,value:264
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-23,value:265
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-66,value:267
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-222,value:268
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-184,value:266
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-6,value:269
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-245,value:270
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-186,value:271
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-214,value:272
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-106,value:273
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-28,value:274
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-252,value:275
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-194,value:276
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-138,value:277
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-9,value:278
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-136,value:279
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-183,value:278
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-255,value:280
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-152,value:281
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-232,value:283
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-131,value:282
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-31,value:284
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-206,value:285
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-287,value:286
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-126,value:287
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-65,value:288
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-182,value:289
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-229,value:290
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-205,value:289
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-34,value:291
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-121,value:292
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-5,value:294
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-11,value:293
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-233,value:295
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-217,value:296
2018-08-30 22:12:24 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-99,value:297
复制代码

  查看日志发现普通的SSH环境在service与dao是单例的情况下,如果存在成员变量存在线程安全问题,结果不是我们预期的结果。

2.解决线程安全问题的简单办法

解决办法一:线程同步sychronized

代码修改为下面代码:

复制代码
package cn.qlq.dao;

import java.util.concurrent.atomic.AtomicInteger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {
    private static Logger log = LoggerFactory.getLogger(UserDaoImpl.class);
    private int i = 1;

    public UserDaoImpl() {
        System.out.println("-----call   UserDaoImpl 无参构造");
    }

    @Override
    public synchronized void saveUser() {
        log.info("------threamName:{},value:{}", Thread.currentThread().getName(), String.valueOf(i++));
    }

}
复制代码

 

清空日志,重启服务进行测试,日志如下:

复制代码
2018-08-30 22:22:58 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-288,value:1
...
2018-08-30 22:23:01 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-41,value:290
2018-08-30 22:23:01 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-299,value:291
2018-08-30 22:23:01 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-100,value:292
.... 2018-08-30 22:23:45 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-40,value:599 2018-08-30 22:23:45 [cn.qlq.dao.UserDaoImpl]-[INFO] ------threamName:http-nio-80-exec-104,value:600
复制代码

发现解决线程安全的问题。

 

解决办法二:使用JDK并发包的AtomicInteger代替in型

复制代码
package cn.qlq.dao;

import java.util.concurrent.atomic.AtomicInteger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {
    private static Logger log = LoggerFactory.getLogger(UserDaoImpl.class);
    private AtomicInteger i = new AtomicInteger(1);

    public UserDaoImpl() {
        System.out.println("-----call   UserDaoImpl 无参构造");
    }

    @Override
    public void saveUser() {
        log.info("------threamName:{},value:{}", Thread.currentThread().getName(), String.valueOf(i.incrementAndGet()));
    }

}
复制代码

总结:

  对于SSH模式的应用,在dao层和service层也存在线程安全问题,所以在dao层和service层我们一般不会定义成员变量,以确保线程安全。但是在Action层由于是多例,一个请求一个实例,所以不会产生现场安全问题。因为操作的就不是同一个实例。

  解决线程安全的方法可以是加synchronized关键字或者使用JDK并发包下的AtomicXXX类代替原来的数据类型。