Java Spring应用程序花费太多时间
我编写了一个SpringMVC代码,用于将PostgreSQL数据库导出到ndjson文件,代码运行正常。但是,其中一个表需要10秒(Careplan)才能保存100条记录 下面是DAO类的代码Java Spring应用程序花费太多时间,java,spring,postgresql,spring-mvc,Java,Spring,Postgresql,Spring Mvc,我编写了一个SpringMVC代码,用于将PostgreSQL数据库导出到ndjson文件,代码运行正常。但是,其中一个表需要10秒(Careplan)才能保存100条记录 下面是DAO类的代码 public List<DafCarePlanParticipant> getCarePlanparticipantByCareTeam(int id) { Criteria criteria = getSession().createCriteria(DafCarePla
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;
}
公共列表getCarePlanparticipantByCareTeam(int id)
{
Criteria=getSession().createCriteria(DafCarePlanParticipant.class,“dp”).add(Restrictions.eq(“careteam”,id));
List dafCareTeam=criteria.List();
回归团队;
}
我在优化这段代码的过程中遇到了瓶颈。我能得到一些帮助吗
谢谢大家! 我认为问题可能是由于
getSession()
造成的。由于getSession()
可能会创建一个新会话,因此每次创建一个新会话并耗尽数据源都会消耗时间
尝试使用
getCurrentSession()
查看是否有任何改进。getSession的作用是什么。您的DafCarePlanParticipant
有多复杂(它真的是一个表还是数据库的一半,其中包含所有关系)并且您真的需要检索所有内容(这就是list
正在做的事情)为什么不懒洋洋地获取内容(使用流
方法)。如果您在列careteam
上没有索引,并且您的表足够大,那么这就是您应该期望的行为。如果这是原因,请在careteam
列上创建一个索引。先生,我该怎么做?懒散的抓取。我不会为你检查你的代码(或者做你的工作)。因此,我不打算下载代码并查看它(如果您认为它会添加到您的问题中,请将代码(片段)添加到您的问题中)。另外,还需要一个分析器,检查什么东西占用了时间。我会试试看!