由于 for 循环内有数千个数据库调用,我面临着性能问题。 有什么出路吗?
for( String cacheKey : moduleCacheMap.keySet() )
{
if( inputCachekey != null && inputCachekey.equalsIgnoreCase( cacheKey ) )
{
CacheItemDto cacheItemDto = moduleCacheMap.get( cacheKey ) ;
cacheList = cacheDao.getCacheList( cacheItemDto ) ;
}
}
这里 cacheDao.getCacheList
每次都会触发一个新的数据库事务。
最佳答案
1) 在单个查询中获取所有需要的行而不是循环,或者
2)如果不需要立即使用所有数据,请制作一个延迟加载的cacheList。
关于java - 循环内的数据库调用有其他选择吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21374880/