views:

233

answers:

8

I am running my java application where i have used threads... i am running this application using ant command on the terminal.. But when i close my terminal or press ctrl+c,then java program which was running stops... Please help me out to solve this as i want to run this program continously...

+1  A: 

If you kill the Java process, Java will no longer be running. If you want the threads to keep running continuously, the Java program must remain active.

Invoking such a program with ant is not usually the way to do it. On Unix-like systems, you would typically run such a program in the background via /etc/init.d startup scripts. In Windows the equivalent would be starting your program as a service, though I'm not sure of the intricacies involved in getting Java to run this way.

If you're running something from a concole - how about just not killing it and minimising the console? If you're starting it from Linux (or Cygwin) just append a & to the end of the command line and the process will run in the background.

Tell us more about your environment, and what compromises you're prepared to put up with (e.g. having a minimised console window sit in the taskbar) and we can help you more. At the moment, the only definitive answer I can give is that "yes - Ctrl-C will kill your program (as intended). If you want it to keep running, don't tell it to stop running." :-)

Andrzej Doyle
A: 

Run the ant command in the background and redirect its output to a file: ant &> my.log &.

NB: this issue does not seems thread related (unless I've misunderstood it).

AndreaG
+1  A: 

You can run your application as a service in linux or windows.

PeterMmm
A: 

It sounds like you want to daemonize your ant task. I'd suggest the following command:

nohup ant &> ant.log < /dev/null &

The nohup will allow the program to continue to run after you close the terminal.

brianegge
+1  A: 

Have a look at the screen command for Linux.

eljenso
A: 

I guess this is desired behavior. If you terminate your application, It gets shut down.

If you wish to run the application in the background you should consider making it a windows service or a deamon.

If you wish to continue running it as a application on *nix, you can consider to use GNU Screen.

Rick
A: 

Try Apache Common Daemon.

J-16 SDiZ
A: 

I'm surprised nobody has mentioned the all-too-famous Java Service Wrapper. This is an excellent piece of software if you are developing long-running processes (a.k.a services).

Jan Jungnickel