'How @Transactional timeout works with multiple dataSource
So here is the example, I have method where I defined timeout=10 seconds for DS1. now this method is also calling another transactional method for DS2. Will time taken by DS2 response also considered here for timeout?
MainService.java
@Transactional(value = "transactionManagerDS1", timeout = 10)
public void tranTest(){
try {
DS1service.sleepDS1(1);
DS2service.sleepDS2(10);
DS1service.sleepDS1(1);
}catch (RuntimeException e){
logger.error(e.getMessage());
}
}
Now these DS1service and DS2service do select sleep for respective seconds
@Transactional(value = "transactionManagerDS1")
public void sleepDS1(int sec) {
SQLQuery query = getCurrentSession().createSQLQuery("select pg_sleep(" + sec + ")");
System.out.println(query.uniqueResult());
}
@Transactional(value = "transactionManagerDS2")
public void sleepDS2(int sec) {
SQLQuery query = getCurrentSession().createSQLQuery("select pg_sleep(" + sec + ")");
System.out.println(query.uniqueResult());
}
here time taken by DS2 query also counted and timeoutException were thrown.Is it correct behaviour?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
