代码之家  ›  专栏  ›  技术社区  ›  Anish

Spring应用程序花费太多时间

  •  -1
  • Anish  · 技术社区  · 7 年前

    我编写了一个SpringMVC代码,用于将PostgreSQL数据库导出到ndjson文件,代码运行正常。然而,其中一个表需要10秒钟(Careplan)才能保存100条记录!

    下面是DAO类的代码

    public List<DafCarePlanParticipant> getCarePlanparticipantByCareTeam(int id) 
    {
            Criteria criteria = getSession().createCriteria(DafCarePlanParticipant.class, "dp").add(Restrictions.eq("careteam", id));
    
            List<DafCarePlanParticipant> dafCareTeam = criteria.list();
    
            return dafCareTeam;
    }
    

    我在优化这段代码时遇到了死角。我能得到一些帮助吗!

    非常感谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   R.yan    7 年前

    我想问题可能是因为 getSession() 自从 getSession() 可能会创建一个新会话,但每次创建一个新会话并耗尽数据源都会耗费时间。

    尝试使用 getCurrentSession() 而是看看是否有任何改进。