2.10 JSM Startup Class

When JSM starts an internal startup class runs. This class loads all JSM service classes and performs an XML transformation to load as many Apache Xalan classes as possible.

A user-defined startup class can be specified by the 'startup.class' property in the manager.properties file.

 

startup.class=com.acme.MyStartup

 

The user-defined startup class needs to implement the Runnable interface. JSM casts this loaded class to a Runnable object and then executes the run method. This happens in the main thread and no additional threads are created to do this task.

The internal startup class and the user-defined startup class run before the JSM starts to accept client and console connections.

Example 1

 

package com.acme ;

 

public final class MyStartup implements Runnable

{

   public void run ()

   {

        try

        {

 

            /*   YOUR CODE GOES HERE   */

 

        }

        catch ( Throwable t )

        {

             t.printStackTrace () ;

        }

   }

}

 

Example 2

 

package com.acme ;

 

public final class MyStartup implements Runnable

{

    private int m_sleepTime = 0 ;

 

    public MyStartup ()

    {

        /*

            JSMManager uses the zero argument constructor

        */

 

        int seconds = 60 * 20 ; // Every 20 minutes

 

        Thread thread = new Thread ( new MyStartup ( seconds ) ) ;

 

        thread.start () ;

    }

 

    public MyStartup ( int seconds )

    {

        /*

            Specify sleep time

        */

 

        if ( seconds <= 0 )

        {

            seconds = 0 ;

        }

 

        m_sleepTime = seconds * 1000 ;

    }

 

    public void run ()

    {

 

        if ( m_sleepTime == 0 )

        {

            /*

                JSMManager call

            */

 

            System.out.println ( "JSM warmup call" ) ;

 

            try

            {

                warmup () ;

            }

            catch ( Throwable t )

            {

                t.printStackTrace () ;

            }

 

            return ;

        }

 

        /*

            MyStartup call with sleep time

        */

 

        while ( true )

        {

            try

            {

                Thread.sleep ( m_sleepTime ) ;

 

                System.out.println ( "MyStartup repeat warmup call" ) ;

 

                warmup () ;

            }

            catch ( Throwable t )

            {

                t.printStackTrace () ;

            }

        }

 

    }

 

    private final void warmup () throws Exception

    {

        System.out.println ( "MyStartup warmup" ) ;

 

        /*   YOUR CODE GOES HERE   */

 

    }

}