public void testConcurrency() throws InterruptedException {
Runnable r1 = new Runnable() {
public void run() {
EmployeeImpl emp1 = new EmployeeImpl("a1");
TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
template.save(emp1);
transactionManager.commit(status);
EmployeeImpl emp2 = (EmployeeImpl) template.get(EmployeeImpl.class, emp1.getId());
assertNotNull(emp2);
assertEquals("First: " + emp1.getMatriculationCode() + " - Second: "+ emp2.getMatriculationCode(), emp1, emp2);
}
};
Runnable r2 = new Runnable() {
public void run() {
EmployeeImpl emp1 = new EmployeeImpl("a2");
TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
template.save(emp1);
transactionManager.commit(status);
EmployeeImpl emp2 = (EmployeeImpl) template.get(EmployeeImpl.class, emp1.getId());