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
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.