English 中文(简体)
i want to continously run my java threads
原标题:

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

最佳回答

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.

问题回答

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." :-)

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

Have a look at the screen command for Linux.

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

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.

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签