You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Megha Bhopale <me...@gmail.com> on 2010/10/07 20:44:38 UTC

[daemon] : Procrun problem

Hi,
I am facing one problem while registering my jar application as windows
service using Procrun.
I hava a main class and a TimerTask class. I am initiating TimerTask from
main class as below.
public class mainClass{
    public static void main(String[] args){
           if ("start".equals(args[0])) start();
            if ("stop".equals(args[0])) stop();
    }

   public void start(){
       mTimer=new Timer();
       timer.schedule(new myTimerTaskClass(),60000);
   }

   public void stop(){
       mTimer.cancel();
   }
}


public class myTimerTaskClass(){
     public void run(){
          System.out.println("Here repeats the timer");
     }
}

I deploy this jar as windows service using procrun. Registration goes fine
without any error. But when i try to start the service, it gives me error
saying, this service started but stopped immediately since it has no tasks
to execute. It is observed that, it calls start() method in main class but
somehow does not start the TimerTask thread and hence the error.

Please help.

Regards,
Megha

Re: [daemon] : Procrun problem

Posted by Mladen Turk <mt...@apache.org>.
On 10/07/2010 08:44 PM, Megha Bhopale wrote:
> Hi,
> I am facing one problem while registering my jar application as windows
> service using Procrun.
> I hava a main class and a TimerTask class. I am initiating TimerTask from
> main class as below.
> public class mainClass{
>      public static void main(String[] args){
>             if ("start".equals(args[0])) start();
>              if ("stop".equals(args[0])) stop();
>      }
>
>     public void start(){
>         mTimer=new Timer();
>         timer.schedule(new myTimerTaskClass(),60000);
>     }
>
>     public void stop(){
>         mTimer.cancel();
>     }
> }
>
>
> public class myTimerTaskClass(){
>       public void run(){
>            System.out.println("Here repeats the timer");
>       }
> }


Which version of procrun you are using?

Your code main method returns immediately, so earlier
procrun versions will just think the application is done.

Anyhow, I'd suggest that you actually wait inside main()
that JVM exits (your worker threads), do eventual cleanup
and then return from the main method.

The upper code is just a Java "hack" which allows the JVM
to continue working even if the main entry method exited.
And this should be forbidden by the law, if you ask me ;)


Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org