-1

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...

azhar_salati
  • 1,474
  • 4
  • 25
  • 51

7 Answers7

1

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
  • 97,637
  • 30
  • 185
  • 225
1

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

Community
  • 1
  • 1
PeterMmm
  • 22,286
  • 12
  • 68
  • 104
1

Have a look at the screen command for Linux.

eljenso
  • 15,950
  • 6
  • 53
  • 62
0

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,086
  • 2
  • 12
  • 26
0

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
  • 26,898
  • 12
  • 70
  • 97
0

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
  • 3,245
  • 1
  • 19
  • 26
0

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
  • 2,034
  • 14
  • 13