Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java program running in background

I have a simple java program which is just a single piece of code that reads from a database and modifies the contents of the database based on certain conditions. Now, what I want is that this program should start automatically at the startup and silently run in the background unless someone kills it from the task manager. I have never done something like this before and don't know exactly how to go about it. Can someone help me out as to how this can be done? Thank you..

like image 756
sachin11 Avatar asked May 05 '12 06:05

sachin11


2 Answers

Follow the these steps to do the job :(Assuming you are using windows and jre is installed )

  • First compile your java program and place the class file at one location.
  • Now create a bat file and place java LOCATION TO THAT CLASS FILE/MyProgram in that.
  • Put your bat file in start up programs
  • Restart the system, you will get your program running in back ground..! Hope this will help you.
like image 87
Ved Avatar answered Sep 23 '22 13:09

Ved


There are two problems here

  1. How to add this program to the startup

    • Windows - Run Java application at Windows startup
    • Linux - Linux start-up script for java application
  2. Run the program as a daemon (background process)

    • Simplest way to do is using a while loop and sleep for required time interval in the while loop. Then perform the database operation.

Also for windows, you can check this JSL http://www.roeschter.com/

Thanks.

like image 42
Manish Mulani Avatar answered Sep 21 '22 13:09

Manish Mulani