List的size()要领明明是public为何还会呈现不行会见的非常。该题目并不是每一次城市呈现,颠末多次实行,该非常一向未在测试情形重现。该接口在完备挪用链路中的堕落次数占总挪用次数的比率为0.01%,有时中遐想到并发题目在周期性时刻内每每是概率性产生。编写模仿多线程情形并发读取公司列表测试代码:
- <mapper namespace="CompanyMapper">
- <select id="getCompanysByIds"resultType="cn.com.shaobingmm.Company">
- select *
- from company
- <where>
- <if test="list != null and list.size() > 0">
- and id in
- <foreach collection="list" item="id" open="(" separator="," close=")">#{id}
- </foreach>
- </if>
- </where>
- </select>
- </mapper>
多线程并发情形下的压测代码
- String resource = "mybatis-config.xml";
- InputStream in = null;
- try {
- in = Resources.getResourceAsStream(resource);
- SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
- final List<Long> ids = Collections.singletonList(1L);
- final SqlSession session = sqlSessionFactory.openSession();
- final CountDownLatch mCountDownLatch = new CountDownLatch(1);
- for (int i = 0; i < 50; i++) {
- Thread thread = new Thread(new Runnable() {
- public void run() {
- try {
- mCountDownLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- for (int k = 0; k < 100; k++) {
- session.selectList("CompanyMapper.getCompanysByIds", ids);
- }
- }
- });
- thread.start();
- }
- mCountDownLatch.countDown();
- synchronized (MybatisBugTest.class) {
- try {
- MybatisBugTest.class.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- } catch (Throwable e) {
- e.printStackTrace();
- } finally {
- if (in != null)
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|