Scheduling a class to run

Hi,
 I have created a java class which checks for txt files in a server folder and delete's them if they exist (Note I am doing this because only the encrypted version of the file should remain in this folder).
 I want to run this class about every 5 or 10 mnutes (one or the other - haven't decided yet).
 Therefore I presume I will need to add a scheduler to the Windows 200 server on which this runs which starts the java class running every 10 minutes.
 I wondered, how do i create this scheduler (never done this type of thing before), and also can I check if the class is already running (in order to stop it trying to run twice at the same time).

Any help would be greatly appreciated.

 

joannapeAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
googlyralphConnect With a Mentor Commented:
Hi,

well, there may be a way of doing this from the Microsoft Java API's, there are things like directX, and registry access. You might be able to write a class that you manually add to the windows scheduler that runs whenever you set it to. Finally, you could write a class, that implements Runnable, and set it to "sleep" for X seconds, X being the number of secodns delay between each run, then when the thread wakes up it does whatever actions are required.

GR.
0
 
Venci75Commented:
Control Panel/Sheduled Tasks
0
 
chintamanidhotreCommented:
Hi joannape,

u can create a batch file for running the java .class file and add that batch file to the scheduler.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
googlyralphCommented:
What about adding a registry key in "run services" with a value of

"javaw com.package.Class param param2"

This will run the java program at system start up, and it will stay in memory running all the time. There is no issue of multiple coppies, as there is only one running.

in hte class you would have somehting like


TIME_TO_SLEEP = 3600;

try{
   deleteFile();
   sleep(TIME_TO_SLEEP);
}catch(interupptedException ie){

}

There is no reason why TIME_TO_SLEEP couldnt be read from a config file etc.

GR.
0
 
daittCommented:
I agree with googlyralph, we can schedule it in java, why need Windows Scheduler.
chintamanidhotre: Please don't propose an answer if your idea is not the first solution posted here and not completely answers the question. You can post a comment instead.
0
 
Venci75Commented:
I could say - why to create a stuff that you don't need -you have a windows scheduler :))
0
 
daittCommented:
as googlyralph said, if we program it ourselves, we won't have the problem of multiple processes doing the same thing. We still can use Windows Scheduler to start the program (or we can setup a service with JavaService or something like that).
But if the task is just deleting txt files in a single folder, I don't think it can take more than 1 minutes. If it's true, using Windows Scheduler is much simpler.
0
 
googlyralphCommented:
if its *just* deleteing temp files then writing a batch file:

echo y | del c:\pathtofiles\*.txt > null

and running this form the Windows Scheduler would be simple, but i assume it is being written in a programming language becuase it has to be slightly more intelligent than deleting some files with a specific extension (though DOS can be fairly clever if you know how to use it).

(note BE CAREFUL WITH THIS CODE, it wont ask to delete, and it wont tell you it is going to / has done)

GR.
0
 
johnchan2000Commented:
joannape,
  You shouldn't have to write any additional code to do this.  If this is for the unix enironment then you can schedule the execution of your program via the usage of the CRON command -- do a man on cron and crontab for more info.  If this is for the MSWindows environment, you can do the same thing with the at command.  The Windows help should provide you plenty of examples on how to run this.

Regards,
John
0
 
nir2002Commented:
Hi,

You can use the java.util.Timer, so you need not depened on the platform you run.
Change your code to extends TimerTask
put your execution in the run() method schedule your task
using schedule(...) method.

see adition information in API

Best regards
Nir
0
 
vemulCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- split points between googlyralph, Venci75 and johnchan2000

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer

0
 
Computer101Commented:
Venci75 and johnchan2000, look for your question in this topic atrea

Computer101
E-E Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.