writing java daemon server: start and stop  
Author Message
calvinwong





PostPosted: 2003-9-23 14:49:00 Top

java-programmer, writing java daemon server: start and stop 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
 
Erwin Moller





PostPosted: 2003-9-23 19:08:00 Top

java-programmer >> writing java daemon server: start and stop 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

 
Lefteris Koutsoloukas





PostPosted: 2003-9-23 19:16:00 Top

java-programmer >> writing java daemon server: start and stop 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" <email***@***.com> wrote in message
news:email***@***.com...
> 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


 
 
nathanz





PostPosted: 2003-9-23 23:31:00 Top

java-programmer >> writing java daemon server: start and stop 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

email***@***.com (calvin01) wrote in message news:<email***@***.com>...
> 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
 
 
onkel.jot





PostPosted: 2003-9-24 0:19:00 Top

java-programmer >> writing java daemon server: start and stop 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