Running tomcat 5.5.15 on Sun JRE 1.5.0_12

I have a situation where a java.util.timer object scheduled to run once per day (by using .scheduleAtFixedRate) is firing two times at once, and it's driving me crazy trying to figure out why. The code excerpts below are my current attempt, but I have tried many variations, such as creating a separate timer object for each event, putting the task and its .run() method in the same class with the timer, and several others. Nothing helps.

The timer periodically creates a report and writes it to a disk file. I am logging the creation of the timer and its schedule and task, and everything looks normal in there, but when the time comes for the timer to fire, I see two entries in the log, as well as getting two outputs merged into one file.

I have another timer in this app that fires every 3 minutes (with .schedule), and works perfectly. Is there something I'm missing about the .scheduleAtFixedRate? Or some bug I haven't been able to find through googling? I've been working on this for two days now, and any and all suggestions welcomed!

Dave


Here are some (hopefully helpful) code excerpts:

This code is run as part of the app startup routine, and creates the appropriate number of exports (3, at 8:00, 9:00 and 15:00):

int numExports = WraProperty.getPropertyInt( Wra.wraProps, "numberOfDispatchExports", 0 ); String exportTimes = WraProperty.getPropertyString( Wra.wraProps, "timeOfDispatchExports", "" );
    if ( numExports > 0 && exportTimes.length() > 0 ) {
        String[] exportTimeList = exportTimes.split( "," );
        new DispatchExportTimer( Wra.wraProps, exportTimeList );
    }


This is the code that intializes the times for the timer created above. My debugging output confirms that the time is set correctly (today vs tomorrow, etc):

public DispatchExportTimer( Properties newProps, String[] exportTimes ) {
       timerProps = newProps;
       Timer thisTimer = new Timer();
       for ( int ii = 0; ii < exportTimes.length; ii++ ) {
           String timeString = exportTimes[ ii ];
           Date exportTime = WraDate.getToday( timeString );
// make sure the time isn't already past; if so, move it to tomorrow
           if ( exportTime.before( new Date() )) {
               exportTime = WraDate.getTomorrow( timeString );
           }
thisTimer.scheduleAtFixedRate( new DispatchExportTask( timerProps ), exportTime, dailyInterval ); Wra.debug( Wra.DEBUG_OBJECTS, "Created new timer event: " + thisTimer.toString() + ", trigger time = " + exportTime,
                   this.getClass().getSimpleName() );
       }
   }



Leaving off the imports, here is the full code of the task class. When I look in the log file, I see two entries written by the first .debug output, with the same (to the second) time stamp:

public class DispatchExportTask extends TimerTask {

   Properties    taskProps;
public DispatchExportTask( Properties newProps ) {
       taskProps = newProps;
   }

   public void run() {
       String    destFile;
       Date    startDate;
try {
           Wra.debug( Wra.DEBUG_ALWAYS, "in .run(): " + this.toString(),
                   this.getClass().getSimpleName());
           // the default start date is "yesterday" at 00:00 (12:00AM)
           startDate = WraDate.getYesterday( "00:00" );
           destFile = taskProps.getProperty( "dispatchFile", "" );
SiteData.Reports.TeleSiraInventory.saveTextReport( destFile, new WraAdmin(), startDate, new Date() );
       } catch ( Exception e ) {
// need to trap exceptions here, to prevent them from propagating up to the timer,
           // which will stop it from executing
Wra.debug( taskProps, Wra.DEBUG_EXCEPTION, ".run(). Exception in task " + this.toString() + ": " + e,
                   this.getClass().getSimpleName() );
       }
   }
}





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to