0

I have to build Java daemon process that once starts will always be working (and listening to an open socket) in Linux, Windows and Mac.

I saw a few solutions on the web, but didn't find anything consistent and widely used. What are developers using for such task?

J.A.I.L.
  • 10,644
  • 4
  • 37
  • 50
user63898
  • 29,839
  • 85
  • 272
  • 514
  • 1
    This is a [shopping question](http://blog.stackoverflow.com/2010/11/qa-is-hard-lets-go-shopping/) and as such not a good fit on SO. – Joachim Sauer Nov 05 '12 at 08:27
  • Possible duplicate: http://stackoverflow.com/questions/534648/how-to-daemonize-a-java-program (also links to at least one cross platform solution) – Andreas Fester Nov 05 '12 at 08:34
  • Possible duplicate: http://stackoverflow.com/questions/326509/java-background-daemon-service-cross-platform-best-pratices – CKmum Nov 05 '12 at 09:20

2 Answers2

2

Simplest way to do it is to create batch file(win)/shell script(linux) and invoke that in inittab (linux) or windows startup. That's makes life easier. In that batch/shell file, simply call java binary with parameters

java background/daemon/service cross platform best practices

Community
  • 1
  • 1
CKmum
  • 641
  • 6
  • 17
  • 1
    You usually need to consider some more details in order to run a Java application as a real background process / daemon. Windows startup folder is not very well suited to run processes as a daemon. – Andreas Fester Nov 05 '12 at 08:32
  • Agreed that windows startup folder may not be the best one but startup could be placed in registry or task as well. Also running as daemon is "start " (http://zeroflag.wordpress.com/2007/05/12/start-command/). If you really need bigger solutions, there are a few around (can't remember names though). – CKmum Nov 05 '12 at 09:15
0

Use javaw from an system execute command in a c program in windows to make the "nicest" deamon in windows. Then have the c program loaded into the registry under startup, or place it in the startup folder, but that is easely edited by your customers which may not be desireable.

Otherwise the command prompt window will keep bugging you/your client.

For linux & mac etc... it's easy, simply load the java command into init.d

Don't know if I'd prefer java as a deamon though.... It's a bit bulky compared to a c deamon.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133