I have an old Spring application witch I upgraded with a new scheduled function.
The application is running in TomCat.
There was already some other working scheduling features which worked fine.
The new scheduling function reads information from an LDAP server and adds information into a mySQL database.
The application worked fine before i added this new function.
It works for a half day after that it hangs in function query.getResultList() on the row marked with <==== below
Could it have something with transactions to do?
I am also using @Autowired BasicDataSource for getting the Connection, it is used for truncating a table in mySQL.
I need some advise please.
/ Peter
Code:
**************** Entity manager configuration
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- Auto scan the components -->
<context:component-scan
base-package="com.cybercom.semesterfu.storage.bo.impl,com.cybercom.semesterfu.storage.dao.impl"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
**************** Persistence configuration
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="userpersistence" transaction-type="RESOURCE_LOCAL">
</persistence-unit>
</persistence>
**************** My new scheduling code
:
@Autowired
BasicDataSource dataSource;
/**
* Reads department and employees into VP:s database
*/
@Scheduled(cron = "${ldap.cron.expression:17 37 * * * *}")
public void handleLdapScheduling()
{
logger.info( "handleLdapScheduling() is updateing 'Departments' and 'Employees'" );
try
{
Connection dbConnection = dataSource.getConnection();
:
**************** Calling the function that hangs
@RequestMapping(value="/vacation/resend", method=RequestMethod.GET)
@Scheduled(cron = "${request.resend.cron:37 13 * * * *}")
public void resendRequests() {
logger.debug("resendRequests() - started");
List<Integer> failedRequests = dayIntervalBo.getFailedRequests();
:
**************** Hanging function (old code working bebare I added the new handleLdapScheduling() code
@Repository("dayIntervalDao")
public class DayIntervalDaoImpl implements DayIntervalDao {
private final static Logger log = LoggerFactory.getLogger(DayIntervalDaoImpl.class);
@PersistenceContext
EntityManager entityManager;
@Override
public List<Integer> getFailedRequests() {
TypedQuery<Integer> query = entityManager.createQuery(
"SELECT DISTINCT di.requestID " +
"FROM DayInterval AS di " +
"WHERE di.requestID <> 0 " +
"AND di.status = 'PENDING'",
Integer.class);
log.debug( "getFailedRequests() After entityManager.createQuery()" );
List<Integer> resultList = query.getResultList() <=======
log.debug( "getFailedRequests() After query.getResultList()" );
return resultList;
}
: