[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

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

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
huabin
Asked:
huabin
5 Solutions
 
CEHJCommented:
0
 
huabinAuthor Commented:
can i do it without the wrapper? in just pure java code? thanks.
0
 
CEHJCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Ajay-SinghCommented:
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
 
objectsCommented:
Just start it with javaw instead of java :)
0
 
objectsCommented:
in linux use:

java MyClass &
0
 
kaliyugkaarjunCommented:
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
 
WebstormCommented:
If you're using Windows :

start javaw App
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now