1
我有一個單獨的對象下面的方法是在多線程環境中運行(Play 2 Java
,MySQL
,Hibernate
):Java的Hibernate的多線程
@Transactional
void deleteItem(int itemId, int userId) {
.....
synchronized(this) {
if(getItemCount(userId) < 2) { // go to database to get the count
return;
}
if(!userOwnItem(itemId, userId) { // check if item belongs to user
return;
}
delete(itemId); // go to db to delete the item
}
....
}
我有一個很難理解爲什麼有時候還是低於1時同時運行。
這實際上是一個單身物件的方法。對不起,我沒有提到它 – user2934804