A threading problem

Hi all,

I have a scenerio where one of my threads must keep an eye on a particular directory once in say 10 mins( it must list the files in the directory once in 10 mins ).Listing is not the problem but how to make this thread run infintely with the specified interval of time .

Thank u

[306 byte] By [ganeshramhere] at [2007-9-30 19:03:39]
# 1
Use java.util.Timer http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
El_Duende at 2007-7-6 23:12:55 > top of Java-index,Administration Tools,Sun Connection...
# 2

Hi,

You can do this by simply using infinite loop having one Thread.sleep(TIME_TO_SLEEP); in side the loop when thread awake it simply call the function for listing file from the directory;

say;

File fDirectoryUnderProcess=new File(directoryPath);

while(true){

try{

File [] fList=listFiles(fDirectoryUnderProcess);

}catch(InterruptedException e){

System.out.println("Exception While Sleep "+e);

}

}

:

:

private File[] listFiles(File fDirectory){

//code for listing files here

}

I Think this may helps you.

softclimax at 2007-7-6 23:12:55 > top of Java-index,Administration Tools,Sun Connection...