• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to run the Java program in the background  RSS feed

 
Celina Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have to write a Java program which sleeps for some particular time, wakes up and sends emails, then sleeps again.
The program needs to run in the background.
It needs to run on both windows and unix...
Does anybody has any idea about how to do it ?
Thanks!
 
Celina Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked out javaw, but would it work in Unix too ?
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea of running in the background is an pperating system concept, not an application one. For example, from a Unix shell, you could type something like:
java MyProgram &
to run the program in the background. That means the program runs, but leaves you free to type other stuff at the command prompt. You can also use:
nohup java MyProgram &
to ensure that your program doesn't exit, even if you close your shell. All output then goes to a file called nohup.out.
As for your application, Thread.sleep(miliseconds) is the easiest way to pause for a set amount of time. If you want to wake up at a certain time, there are some timer classes that can probably help you.
 
William Barnes
Ranch Hand
Posts: 1049
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This type of program is called a "daemon".
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in Windows:
start java MyProgram
 
Wayne Lemmon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried:
start java MyProgram

but it opens a new command window. I am looking to run this in the back ground with out the window.
Thanks for your help.

Wayne
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wayne Lemmon wrote:I tried:
start java MyProgram

but it opens a new command window. I am looking to run this in the back ground with out the window.


Did you read the part of this 7 year old topic about javaw?

Henry
 
Wayne Lemmon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javaw worked!! I am now a happy camper.. or should I say coder
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!