I am writing one post service, to log my activities and as it is activity service it is calling 10 times per second so i have to control it by executing asynchronously, so i went for spring task executor and i am using spring transaction manager to get session, but if i call from task executor run method i am getting following exception.
Exception in thread "executorWithPoolSizeRange-1" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
you can check following my code
public void saveActivityLogs(final List<UserActivityEntity> activityLogs,final String clientIP,final int clientPort){
logger.info("Saving activiytlogs");
/*for(UserActivityEntity activitylog:activityLogs){
activitylog.setClientIp(clientIP);
activitylog.setClientPort(clientPort);
this.commonDAO.saveActivityLogs(activitylog);
} */
executorWithPoolSizeRange.execute(new Runnable() {
public void run() {
addActivityLogs(activityLogs,clientIP,clientPort);
}
});
}
/**
this method will call from above one
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addActivityLogs(List<UserActivityEntity> activityLogs,String clientIP,int clientPort){
for(UserActivityEntity activitylog:activityLogs){
activitylog.setClientIp(clientIP);
activitylog.setClientPort(clientPort);
this.commonDAO.saveActivityLogs(activitylog);
}
}