Hello All,
I am having an issue where a running thread is unable to return new records from the database. The thread seems to only return the current state of the DB for the first execution of my Query... any subsequent changes to the DB are not recognized until my process is restarted. I know this is not a "COMMIT" issue because I have tested with another process.
Hibernate 3
MySQL 4.1
I am using the HibernateUtil.java file which ships with Hibernate 3 and the sample application.
Any help is greatly appreciated!
Thanks in advance,
Geoff
Configuration File:
Code:
<property name="connection.url">jdbc:mysql://localHost/???????</property>
<property name="connection.username">????????</property>
<property name="connection.password">????????</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">50</property>
<property name="c3p0.timeout">1800</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
Polling Thread:
Code:
public class DequeueManager extends Thread {
private static Logger log = Logger.getLogger(DequeueManager.class.getName());
private static Integer threadPoolSize = new Integer(ConfigLoader.getProperty("dequeueThreadPoolSize"));
private static ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newFixedThreadPool(threadPoolSize);
/** Creates a new instance of DequeueManager */
public DequeueManager() {}
public void run(){
/** Obtain the ThreadLocal Session object */
Session sess = HibernateUtil.getSession();
while(true){
/**
* Create all new DAO objects + transactions. Only doing this as
* an attempt to return the new data... shouldn't really be necessary
*/
ActiveCallDAO callDAO = new ActiveCallDAO();
List calls = callDAO.getQueuedCalls();
log.debug(calls.size() + " Dequeueable calls found.");
/** Check to see if any calls were returned */
if(calls.size() > 0){
ListIterator i = calls.listIterator();
while(i.hasNext()){
ActiveCall call = (ActiveCall)i.next();
/** update the state of the call which is about to be processed */
HibernateUtil.beginTransaction();
call.setCallState(ActiveCall.CALL_DEQUEUE);
sess.save(call);
HibernateUtil.commitTransaction();
/** execute the dequeue attempt for this call */
DequeueWorker worker = new DequeueWorker(call);
threadPool.execute(worker);
}
}else{
try{
/** No calls found, take a nap so we don't destroy CPU */
Thread.sleep(2000);
}catch(InterruptedException e){
log.error(e.toString());
}
}
/**
* commit the TX which is started when we create our new
* DAO.. not sure if this will help... but worth a shot
*/
HibernateUtil.commitTransaction();
}
}
}
Data Access Object:
Code:
public class ActiveCallDAO {
private static Logger log = Logger.getLogger(ActiveCallDAO.class.getName());
/** Creates a new instance of ActiveCallDAO */
public ActiveCallDAO() {
HibernateUtil.beginTransaction();
}
/**
* Used to return a List of all the calls which are currently sitting in Queue.
* This method uses a date/time stamp to decide when to attempt the next
* dequeue
*
* @since 1.0
*/
public List getQueuedCalls(){
Session sess = HibernateUtil.getSession();
Query query = sess.createQuery("FROM com.connectfirst.intelliqueue.model.ActiveCall call WHERE call.callState = ? AND call.nextDequeueTime > ? ORDER BY call.enqueueTime ASC");
query.setParameter(0, ActiveCall.CALL_QUEUED);
query.setParameter(1, new java.util.Date());
return(query.list());
}
}