For anyone who might be interested, this is what I ended up with for a scheduler:

public class AServletContextListener implements ServletContextListener
{

    private ScheduledExecutorService executor;


    /**
     * Constructs AServletContextListener object.
     */

    public AServletContextListener()
    {
    }


    /**
     * Invoked when context is initialized.
     *
     * @param    sce        triggering ServletContextEvent
     */

    public void contextInitialized( ServletContextEvent sce )
    {
        if ( executor == null )
        {
            executor = Executors.newSingleThreadScheduledExecutor();

            Calendar firstRunTime = new GregorianCalendar();
            firstRunTime.set( Calendar.HOUR_OF_DAY, 12 );
            firstRunTime.set( Calendar.MINUTE, 0 );
            firstRunTime.set( Calendar.SECOND, 0 );
            firstRunTime.set( Calendar.MILLISECOND, 0 );

            executor.scheduleAtFixedRate(
                new ARunnable(),
firstRunTime.getTimeInMillis() - System.currentTimeMillis(),
                1000 * 60 * 60 * 24,
                TimeUnit.MILLISECONDS );
        }
    }


    /**
     * Invoked when context is destroyed.
     *
     * @param    sce        triggering ServletContextEvent
     */

    public void contextDestroyed( ServletContextEvent sce )
    {
        if ( executor != null )
        {
            boolean isTerminated = false;

            executor.shutdown();

            do
            {
                try
                {
                    isTerminated = executor.awaitTermination(
                        1, TimeUnit.SECONDS );
                }
                catch ( InterruptedException ignore )
                {
                }
            }
            while ( !isTerminated );

            executor = null;

            Thread.yield();
        }
    }

}

Thanks for all the suggestions and pointers.

-Terence


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to