Solved

Run my Java program as a deamon process (Linux + Java)

Posted on 2006-07-05
10
246 Views
Last Modified: 2012-05-05
Hi,

I have a java program, and I would like to run it as deamon prcoess,

This is what I mean: when I type "java myProgram" on the command line, the program should be running in the background, and the system will return to the command line for another command.
The java program only tereminte when the computer reboots.

Anyhelp will be appericiated.
0
Comment
Question by:huabin
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 17044580
0
 

Author Comment

by:huabin
ID: 17044611
can i do it without the wrapper? in just pure java code? thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17044637
No. You can't really run a program in the background in Windows unless you run it as a service. This requires native code.

You can start a program using javaw.exe and then close the command window leaving the process running, but that's messy
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 100 total points
ID: 17045281
You can do the same thing by running a java process that starts the actual java program, as

while(true) {
    Process process = Runtime.getRuntime().exec(...);
    int code = process.waitFor();
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 17047156
Just start it with javaw instead of java :)
0
 
LVL 92

Expert Comment

by:objects
ID: 17047158
in linux use:

java MyClass &
0
 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 100 total points
ID: 17048369
Chk this link

http://www.jcp.org/en/jsr/detail?id=96

it is Java Daemon JSR 96 [JSR about developing cross platform daemons]

0
 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 100 total points
ID: 17049248
If you're using Windows :

start javaw App
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now