我目前有一个大型游戏,其中许多连接正在写入我们的数据库。在玩家采取了各种动作(通常是重要事件)之后,我将更新玩家记录。为此,我经常利用以下内容:
/**
* Commits an object to the database & saves it
* @param entity - the entity to commit to the database
*/
@Transactional
public void updateActionList(List<DbEntity> dbEntityList) {
try(Session session = Statics.getFactory().openSession()) {
session.beginTransaction();
int counter = 0;
for(DbEntity entity : dbEntityList) {
session.saveOrUpdate(entity);
counter++;
if(counter % 20 == 0) {
session.flush();
session.clear();
}
}
session.getTransaction().commit();
}
catch(Exception e) {
Statics.NATIONS_LOGGER.log(Level.SEVERE, "Error", e);
e.printStackTrace();
}
}
但是,当应用程序尝试关闭时,我们遇到了一个大型堆栈跟踪,当我们的Hibernate运行时,只有 发生:
在巨大的堆栈跟踪中,我注意到以下内容:
[17:14:34] [Spigot Watchdog Thread/ERROR]: Current Thread: Hibernate Connection Pool Validation Thread
[17:14:34] [Spigot Watchdog Thread/ERROR]: PID: 58 | Suspended: false | Native: false | State: TIMED_WAITING
[17:14:34] [Spigot Watchdog Thread/ERROR]: Stack:
[17:14:34] [Spigot Watchdog Thread/ERROR]: sun.misc.Unsafe.park(Native Method)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[17:14:34] [Spigot Watchdog Thread/ERROR]: java.lang.Thread.run(Thread.java:748)
我的直觉告诉我,我的Hibernate提交做错了什么。有人看到我的数据库操作有什么明显的错误吗?