Q:

How can I run my java program in a timed loop?

I am trying to get my program to run every 5 minutes. Can anyone tell me how to achieve this? I'm fairly new to java, here's what I have so far. This is a program that prints processes to a text file and then calls that text file to display its data. It would be nice to have this run every 5 minutes.
import java.io.*;
import java.util.StringTokenizer;

public class getProcesses
{

 private String GetProcessListData()
 {
 Process p;
 Runtime runTime;
 String process = null;
 try {
 System.out.println("Allow me to hack your system and see what you have open...");

 //This will let us access windows in order to make this program possible
 runTime = Runtime.getRuntime();

 p = runTime.exec("tasklist");

 InputStream inputStream = p.getInputStream();
 InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
 BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

 String line = bufferedReader.readLine();
 process = "&";
 while (line != null) {
 line = bufferedReader.readLine();
 process += line + "&";
 }

 //As we learned in class, we have to close whatever we open
 bufferedReader.close();
 inputStreamReader.close();
 inputStream.close();

 //The following output is a quote from Portal
 System.out.println("System has been modified. Thankyou and Goodbye.");
 } catch (IOException e) {
 System.out.println("Uh oh, looks like we found an IOE");
 e.printStackTrace();
 }
 return process;
 }

 private void showProcessData()
 {
 try {

 String proc = GetProcessListData();

 OutputStreamWriter outputStreamWriter =
 new OutputStreamWriter(new FileOutputStream("ProcessList.txt"));
 BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);

 StringTokenizer st = new StringTokenizer(proc, "&");

 while (st.hasMoreTokens()) {
 bufferedWriter.write(st.nextToken());  
 bufferedWriter.newLine();               
 }

 //This will close the outputStreams
 bufferedWriter.close();
 outputStreamWriter.close();

 } catch (IOException ioe) {
 ioe.printStackTrace();
 }

 }

 @SuppressWarnings("resource")
public static void main(String[] args) throws IOException
 {
 getProcesses gpl = new getProcesses();
 gpl.showProcessData();

 BufferedReader in = new BufferedReader(new FileReader("ProcessList.txt"));

 String line;
 while((line = in.readLine()) != null)
 {
     System.out.println(line);
 }
 }
}

Any help is appreciated, thankyou.

A:

you should set up a scheduled task (Windows) or cron job (unix) to launch the command "java -jar myprogram.jar" every five minutes.

