-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Help with "polling" Thread not returning new DB re
PostPosted: Sun Apr 24, 2005 11:26 am 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
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());       
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 11:47 am 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
Nevermind... I figured it out. It was one of those "duh" moments which only occur after you have been writing code for hours and hours without sleep :)

There was an error in my query logic :(

-Geoff


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.