Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Need to run the Java program in the background

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked out javaw, but would it work in Unix too ?
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This type of program is called a "daemon".
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in Windows:
start java MyProgram
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javaw worked!! I am now a happy camper.. or should I say coder
 
reply
    Bookmark Topic Watch Topic
  • New Topic