the method of entering the library in service needs to be tested in the case of multithreading, and then two threads are opened to execute the service method in a loop, but there are a lot of problems, including the following situations.
- both threads are halfway through execution and then terminate with an error. The database has several pieces of data
- both threads are executed only once, and the database has one piece of data each
- Database has no data
related codes
@Rollback(value = false)
@Test
public void test() throws Exception {
// ,
// for (int i = 0; i < 10; iPP) {
// normal(Thread.currentThread().getId(), i);
// }
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; iPP) {
normal(Thread.currentThread().getId(), i);
}
}
});
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; iPP) {
normal(Thread.currentThread().getId(), i);
}
}
});
thread1.start();
thread2.start();
}
public void normal(long id, int n) {
auditLoggingService.insertAuditLogging("" + id + "/" + n, 56, 6, 0,
BaseConstants.AuditLoggingOperatorType.MODIFY, "", "", 0, "", "", "", "", BaseConstants.UserInfo.USER_CAT_INNER, "yangyan", "");
}
error message
- can sometimes be executed successfully with no error message, but there is no information in the database
- Returning cached instance of singleton bean "org.springframework.transaction.interceptor.TransactionInter