Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scheduling a class to run

Posted on 2002-06-21
12
Medium Priority
?
209 Views
Last Modified: 2011-09-20
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.

 

0
Comment
Question by:joannape
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +5
12 Comments
 
LVL 1

Accepted Solution

by:
googlyralph earned 300 total points
ID: 7098329
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
 
LVL 9

Expert Comment

by:Venci75
ID: 7098358
Control Panel/Sheduled Tasks
0
 

Expert Comment

by:chintamanidhotre
ID: 7098445
Hi joannape,

u can create a batch file for running the java .class file and add that batch file to the scheduler.
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 1

Expert Comment

by:googlyralph
ID: 7098467
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
 
LVL 3

Expert Comment

by:daitt
ID: 7098589
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
 
LVL 9

Expert Comment

by:Venci75
ID: 7098596
I could say - why to create a stuff that you don't need -you have a windows scheduler :))
0
 
LVL 3

Expert Comment

by:daitt
ID: 7098654
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
 
LVL 1

Expert Comment

by:googlyralph
ID: 7098673
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
 
LVL 1

Expert Comment

by:johnchan2000
ID: 7104258
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
 
LVL 2

Expert Comment

by:nir2002
ID: 7167454
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
 
LVL 5

Expert Comment

by:vemul
ID: 7888049
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
 
LVL 1

Expert Comment

by:Computer101
ID: 7959700
Venci75 and johnchan2000, look for your question in this topic atrea

Computer101
E-E Admin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question