schedule java program - java

I want to run my java program in regular interval , lets say, in every 3 hours. I am thinking to write a .bat file and put command to call java class. But what is the best way to run .bat regularly in windows xp. Thanks in advance. I dont want to use third party tool.

Windows scheduled tasks are built for exactly that purpose.
You can run things on multiple schedules (so you can get your every-three-hour behaviour) and you can get your code to run whether or not logged in.
The multiple scheduling is a bit tricky. You basically set it up as a daily task to start with but, near the end, it will ask you if you want to do advanced features.
Select yes then you can set up multiple schedules at that point.

If you want a pure Java Based solution you can try QUARTZ SCHEDULER. But as paxdiablo already mentioned, Windows Task Scheduler will do that as well.

Related

How to schedule a java program to run daily in Windows?

I have written a Java program which retrieves Google data till present date using Google Analytic API and export it as CSV file. I want this program to run daily so that data in the CSV file will be up to date. How can I achieve this?
You can use the Windows Task Scheduler (see tutorial) to start any program; for Java, you will probably want to create a batch file to run your Java program, then use the Scheduler to run the batch file. The Scheduler provides a "Create Basic Task" wizard for setting up these schedules.
You can also use an executable JAR instead of a batch file, provided that Windows has a file association between JAR files and Java.
You may need to specify the start directory if your task performs IO - see this thread.
Schedule Via Java
Use a ScheduledExecutorService and the method scheduleAtFixedRate with a TimeUnit of Day. Your program will wait a day and then do what it has to do.
Of course your computer has to be on. If that is an issue, it might be better do something like this using Google App Engine.
Have a look at Windows Task Scheduler. Task scheduling can be found under all programs -> accessories -> system tools -> scheduled tasks.

java - how reflect a long running workflow process in GUI?

I have a workflow of functions that eventually lead to a deployment of something.
the steps are as followed:
run a python script the produces some output.
run a bash script that copies this output to a given location
run a bash script (depending on the output of 1,2) that runs a java program (running make take few hours)
run another bash script on this output - final step
i want to be able to initiate this workflow from a GUI giving a set of parameters.
Then, I want to be able to get status reports of each step - so that the running user will know which step is currently running.
The main issue here is that each of the steps may take long time to finish.
My experience with developing GUI in java is limited.
Any advice on the direction I should go to?
If you really want to write this in Java, then you should try to find a good wizard library. See this question for some details.
Then, if at all possible that your scripts provide some feedback like the percentage of the operation completed then you could have a JProgressBar for each step independently and an overall one to show the user an idea of how much is done at any moment.

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..
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.
There are two problems here
How to add this program to the startup
Windows - Run Java application at Windows startup
Linux - Linux start-up script for java application
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.
first create you jar bash and then add it to you crontab task list.

connect to the internet using java

Whenever i want to connect to internet,i double click a connection icon(i created it earlier where username and password(for broadband) are stored) and click connect.The icon is in the network places(Windows XP)
May i know how to launch this connection from java or any other language? (I am asking this because my Internet Service Provider doesn't charge anything between 2 AM and 8AM :-) )
Creating a system task to run the program. You shouldn't need Java to execute a program on windows.
To use Scheduled Tasks in XP: http://support.microsoft.com/kb/308569
This is going to be unnecessarily difficult with Java, I believe. You'd have to write some native code to do the job for you, at which point you may as well write your whole program in C# or C++ anyway.
But, since you asked for a Java approach, you might want to look at the Robot class. It lets you move the mouse to a specific location on the screen, click, and otherwise automate the manual actions that you are doing. It's a very fragile solution.
Alternatively, if you can figure out what command the network connection shortcut is invoking, you can directly invoke it from Java using Runtime.exec.
(I don't really see why Java is good for this task, though.)

Run an application as background process

I have developed a Java application. I want to run it as a background process.
It should not be displayed as Running Application in task Manager, but it should be displayed in Processes List.
Help me out.
Regards,
Jigar
I've edited your question since it's a pure windows issue.
I would suggest you to take a look at ways to run your java application as a windows service.
In addition to Command Prompt option given by Rafael Roman, we can also schedule task through Control Panel -> Scheduled Tasks -> Add Schedued Task. For more info:
http://technet.microsoft.com/en-us/library/cc738106(v=ws.10).aspx
There's no need for complex solutions.
use the at commando and create a bat that runs your program.
type in any cmd windows:
at 10:00 c:\run_my_script.bat
remember to replace 10:00 to a time 1 minute after the current time of your machine

Categories