TimerTask Consuming CPU Utilization

Viewed 16

I am implementing a transaction processing system in JAVA, I need to schedule a task that will run after 60 seconds without response from the host, the timer task increases the CPU utilization, what better way can timed task be handled

void instantiateTimer()
{   
        String errormsg="";
        TimerTask elapsetask=new TimerTask()
        {
            public void run()
            {
                try
                {  
                    //job to do
                    timer.purge(); 
                }
                catch(IOException ex)
                
                    logger.error(errormsg);
                } 
                catch(Exception ex)
                {            
                    errormsg="["+TID+"] general error sending msg-to-initiator: "+ex.getMessage()+"\n"+Arrays.toString(ex.getStackTrace());  
                    logger.error(errormsg);
                } 
            }
        };
        endtime=startmillsec+slpduration;
        Date scheduleTimeTask=new Date(startmillsec+slpduration);
        logger.info("scheduled time: "+startmillsec);
        timer.schedule(elapsetask, scheduleTimeTask);
}
0 Answers
Related