遗留系统采用了spring,jpa框架,经常有系统挂死的问题,发现问题如下:
spring配置中,fitApDao被注入进了AcPmSampleCollectSchedule类,fitApDao里面包含jpa 的entityManager
AcPmSampleCollectSchedule中的代码,源代码不是这样的,做了简写,
public void start() throws InterruptedException { Listacs = deviceCacheService.getCacheAcs(); for (final Ac ac : acs) { new Thread(new Runnable(){ public void run(){ fitApDao.doSomething(); } }).start(); } }
由上可以看到,fitApDao在多线程的环境被使用。
这种情况下,系统过段时间下会挂死,因为数据库调用频繁的时候,entitymanager会挂死,请问如何配置和修改?谢谢
该用线程池,另外建议将dao与schedule解耦