• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make a java program run always

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a Java program which need to run always. it has to keep on running. How can i create that . Please advise.

Thanks in advance.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just create a loop in your application that never stops, and don't return from the main() method. For example:
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really an intermediate problem.
 
Karthikean Konangi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all your replies.
I guess, i didnot ask the question properly.

My question is " I already wrote a Java program with infinate loop.But how can i make this job as a cron/ scheduled job / some job so that, it has to run always in the server. I should be able to start/stop the process and close the command prompt. How can i do this??
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess, if you're on Windows, anyway, set it [Windows] up to launch the application you need at start, or, launch a batch file that launches the application you need.

Is there a way to do this in the Java library? I don't know, as I hear it tries not to be OS-specific.

I suppose you could use the Java Native Interface, maybe. Or maybe I'm off track.
[ June 25, 2008: Message edited by: Christopher Young ]
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several ways to run Java programs as Windows services, that start when Windows starts. Search for "java windows service" on Google.

On Unix or Linux, you can add a startup script somewhere in the /etc folder to start your program at boot. How this works exactly depends on what flavour of Unix or Linux you're using (read the documentation of your OS).
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using java.util.TimerTask

A task that can be scheduled for one-time or repeated execution by a Timer.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimerTask.html

Here is a sample code:;Hope this helps..

-Vaibhav

[edit]Add code tags. CR[/edit]
[ June 25, 2008: Message edited by: Campbell Ritchie ]
 
Karthikean Konangi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

Again I have to intiate TestScheduler process and, if I close the Command Prompt the process will close automatically.

And my OS is Sun Solaris 5.8


Please advise.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
search for "Quartz job Scheduler" for job scheduling . and make a simple java program which takes START OR STOP command , which in turn start/stop your job class ..
 
vaibhav gupta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use invoke the process in background (as you said you are using solaris os)

See: http://learnlinux.tsf.org.za/courses/build/shell-scripting/ch12s02.html

e.g.

java TestScheduler &

After this you can even close the command prompt.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can run a java program as a daemon process in UNIX environment by using Java Service Wrapper. Please see this url -
Java Service Wrapper
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Vaibhav g" please read your private messages again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic