aspose file tools*
The moose likes Threads and Synchronization and the fly likes Process stoping and starting for outside a java app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Process stoping and starting for outside a java app" Watch "Process stoping and starting for outside a java app" New topic
Author

Process stoping and starting for outside a java app

hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Hi all
I've got a litte problem.
I have an ap that runs ans starts another java app as a daemon on a server
I am starting the daemon app in the following way

my questions is:
1. Will this process keep runing on the unix system after i log off (can use nohup or anything like that, will also need to run in windows)
2. How can I shut this process down without killing
the process (meaning invoke it's shut down sequence, the app is handling request and if i just kill it the request queue will not be dequeued )
Any help in this would be very great


Any Body can be paid to write good code, but brilliant code can only come from passion
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Originally posted by hennie louw:
Hi all
I've got a litte problem.
I have an ap that runs ans starts another java app as a daemon on a server
I am starting the daemon app in the following way

my questions is:
1. Will this process keep runing on the unix system after i log off (can use nohup or anything like that, will also need to run in windows)
2. How can I shut this process down without killing
the process (meaning invoke it's shut down sequence, the app is handling request and if i just kill it the request queue will not be dequeued )
Any help in this would be very great

Hi Hennie,
your runtime object, rt, has a method called addShutdownHook. The paramater to this method is a Thread object, which gets run before the program exits. Thus, you would put clean up code inside of a thread object's run method, pass the thread to the addShutdownHook method, and all would be well.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Java Regular Expressions
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Originally posted by Max Habibi:
your runtime object, rt, has a method called addShutdownHook. The paramater to this method is a Thread object, which gets run before the program exits. Thus, you would put clean up code inside of a thread object's run method, pass the thread to the addShutdownHook method, and all would be well.

Hi Max
i understand this but what i am asking is how do i get the jvm of this background process to invoke it's shutdown hooks??
Let say we run it on linux, by typing
killalll -9 java
will this not forcefully terminate the process or will it send the process a termination signal and allow the jvm to move through its normal shutdown hooks ???
Also can anybody tell me if by starting the process in this way will the process keep runing on a machine after i've logged off??? like tomcat does or will it terminate ?
Please help with this asap
thanks
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hennie,
I'm not sure I've been clear. Terminiating the parent process(the one that had the rT object) will cause the Thread to run. That Thread, in turn, will terminate the child process. So the answer to your question is yes, assuming that the jre on that system is bug free.
This should be easy enough to test.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Originally posted by Max Habibi:
Hennie,
I'm not sure I've been clear. Terminiating the parent process(the one that had the rT object) will cause the Thread to run. That Thread, in turn, will terminate the child process. So the answer to your question is yes, assuming that the jre on that system is bug free.
This should be easy enough to test.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4

Max,
Sorry if I have been stateing my problem wrong, what I want is for the child process to keep running in the background even after the main program has stoped, this app is a basic start and stop script for the child process that is the actual server app
So wat I want is for me to log on to a machine and
run "java [mainapp] start" and the have the console return and the child process running , log off and mabe over 2 hours or so long on again and run "java [mainapp] stop"
Please let me know if there is still some sort of misunderstanding
Thanks for the info so far( just what i needed for a diffrent app im working on )
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Hennie,
Looks like I misunderstood your question. Ok, as to the answer you really wanted:
You shouldn't have to do anything: the new process should be indepentent of the spawning process. I know that it works this way in win2k. I would suggest a simple test. I would also suggest using java in silent mode.
Best regards,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Originally posted by Max Habibi:
Hi Hennie,
Looks like I misunderstood your question. Ok, as to the answer you really wanted:
You shouldn't have to do anything: the new process should be indepentent of the spawning process. I know that it works this way in win2k. I would suggest a simple test. I would also suggest using java in silent mode.
Best regards,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4

Hi
Thanks for the info bu what do you mean with "java in silent mode" ?
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

You might want to look into RMI. I think it would serve your purpose much more cleanly. Of course the RMI daemon will need to be running all the time, but this is not really a problem since it just sits there doing nothing till its called upon. Else you will need to use sockets to get a signal to your java app to shut down.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Process stoping and starting for outside a java app