• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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: 3064
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: 23956
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
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic