writing java daemon server: start and stop

Discussion in 'Java' started by calvin01, Sep 23, 2003.

  1. calvin01

    calvin01 Guest

    Dear everyone,

    I am trying to write a server program to do some monitoring.
    I am using Windows 2000 platform.
    I've seen that there is some server program can start server by
    specifying command like "server start" and stop it like "server stop".

    I am wondering how to do it in java language since java is running in
    the JVM.
    1. Is it prossible to send signal to kill the process just like c lang
    ?
    2. Do java have process ?
    3. How about if java thread can be killed by those deprecated method
    like thread.stop(), can I find the current running thread and stop it
    ?
    4. Any suggested method to do the server stop which can stop the
    current running java program in JVM ?

    Thank you for helping
    Calvin
    calvin01, Sep 23, 2003
    #1
    1. Advertising

  2. calvin01

    Erwin Moller Guest

    calvin01 wrote:

    > Dear everyone,
    >
    > I am trying to write a server program to do some monitoring.
    > I am using Windows 2000 platform.
    > I've seen that there is some server program can start server by
    > specifying command like "server start" and stop it like "server stop".
    >
    > I am wondering how to do it in java language since java is running in
    > the JVM.
    > 1. Is it prossible to send signal to kill the process just like c lang
    > ?


    Not sure under Win2000, I guess it is possible.

    > 2. Do java have process ?
    > 3. How about if java thread can be killed by those deprecated method
    > like thread.stop(), can I find the current running thread and stop it
    > ?
    > 4. Any suggested method to do the server stop which can stop the
    > current running java program in JVM ?


    when you give a command like 'java yourprogram' you start a JVM.
    This JVM will run untill your program terminates.
    SO the most 'natural' way of implementing your server would be something
    like this:
    1) start your app by typing java yourapp
    2) start some thread that holds your logic.
    // in a Runnable classdef:
    while (bKeepRunning){
    // your logic
    }

    3) let the thread finish naturally if some boolean (bKeepRunning) changes
    value.
    4) read the commandline, or mayby via some GUI, and decide when to change
    the value for bKeepRunning.

    In this way you start up and shut down without having to worry about PID and
    such.

    Hope this helps!
    Regards,
    Erwin

    >
    > Thank you for helping
    > Calvin
    Erwin Moller, Sep 23, 2003
    #2
    1. Advertising

  3. One thought is to have your server a listening socket to receive
    adinistrative
    commands such as start and stop.
    You will also need to implement simple administration clients (to send
    commands to
    your server), to decide on the format of the commands (something simple like
    pre-defined
    text strings) and you will also have to worry about authentication (ssl
    maybe?).
    It's alot of work but it is a nice extensible solution.


    "calvin01" <> wrote in message
    news:...
    > Dear everyone,
    >
    > I am trying to write a server program to do some monitoring.
    > I am using Windows 2000 platform.
    > I've seen that there is some server program can start server by
    > specifying command like "server start" and stop it like "server stop".
    >
    > I am wondering how to do it in java language since java is running in
    > the JVM.
    > 1. Is it prossible to send signal to kill the process just like c lang
    > ?
    > 2. Do java have process ?
    > 3. How about if java thread can be killed by those deprecated method
    > like thread.stop(), can I find the current running thread and stop it
    > ?
    > 4. Any suggested method to do the server stop which can stop the
    > current running java program in JVM ?
    >
    > Thank you for helping
    > Calvin
    Lefteris Koutsoloukas, Sep 23, 2003
    #3
  4. All the Java-based servers I've seen that have this sort of
    functionality (such as Tomcat) use sockets to connect to the running
    server. The server listens for special messages on a specific port,
    and if it sees the "kill" message, it stops all its threads.

    I wouldn't use the deprecated Thread methods, they were removed for a
    reason, and there is an explaination of how to correctly stop threads
    in the Javadoc.

    -Nathan

    (calvin01) wrote in message news:<>...
    > Dear everyone,
    >
    > I am trying to write a server program to do some monitoring.
    > I am using Windows 2000 platform.
    > I've seen that there is some server program can start server by
    > specifying command like "server start" and stop it like "server stop".
    >
    > I am wondering how to do it in java language since java is running in
    > the JVM.
    > 1. Is it prossible to send signal to kill the process just like c lang
    > ?
    > 2. Do java have process ?
    > 3. How about if java thread can be killed by those deprecated method
    > like thread.stop(), can I find the current running thread and stop it
    > ?
    > 4. Any suggested method to do the server stop which can stop the
    > current running java program in JVM ?
    >
    > Thank you for helping
    > Calvin
    Nathan Zumwalt, Sep 23, 2003
    #4
  5. calvin01

    jot Guest

    Hi Calvin,

    > 1. Is it prossible to send signal to kill the process just like c lang?

    Yes.

    > 2. Do java have process ?

    Any current JVM (1.3 or 1.4 version) is one process.

    > 3. How about if java thread can be killed by those deprecated method
    > like thread.stop(), can I find the current running thread and stop it
    > ?

    You cannot find a thread in a VM if you are not inside the VM.

    > 4. Any suggested method to do the server stop which can stop the
    > current running java program in JVM ?

    Just use kill to stop the process. You might run into problems with
    open resources, depends on what you have open (files, databases,
    ....). Most of it should be closed on exit.

    The nice way is to register a shutdown hook via
    Runtime.getRuntime().addShutdownHook(). Using kill -HUP on your process
    stops the JVM gracefully and executes your hook. While this works for
    most *nix, i'm not sure about windoze. In addition, signal handling
    depends on your SDK vendor (SUN, IBM).

    jot
    jot, Sep 23, 2003
    #5
  6. calvin01

    hhk

    Joined:
    May 30, 2009
    Messages:
    1
    http://wajidmehraj.blogspot.com

    A good link to java program daemons
    hhk, May 30, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Paul Calderone
    Replies:
    0
    Views:
    441
    Jean-Paul Calderone
    Mar 20, 2009
  2. Floris Bruynooghe
    Replies:
    1
    Views:
    437
    Floris Bruynooghe
    Mar 24, 2009
  3. Thomas Uehlinger
    Replies:
    0
    Views:
    146
    Thomas Uehlinger
    Feb 8, 2005
  4. Grischa Schuering
    Replies:
    1
    Views:
    488
    David Efflandt
    Sep 30, 2003
  5. Justin C
    Replies:
    2
    Views:
    110
    Justin C
    Nov 22, 2013
Loading...

Share This Page