+2  A: 

You should find out which thread interrupts that thread. Threads don’t do that on their own.

Bombe
please, can u tell me how i know which thread interrupts that thread
Catch the exception and try to analyse the Exception object. There should be interesting information in it.
furtelwart
+3  A: 

I must agree Bombes comment: threads don't get interrupted on their own. Contrary to Jokis comment - they're not interrupted when a thread context swap takes place either (in fact, if a thread sleeps, it will surrender it's quantum to any thread that has work to do, but I digress).

Furthermore, I would advise an alternative means of communication than polling for files. You cannot be certain, for example, that once you have spotted a file, that it has been completely written without extra work from the file-writer (such as renaming it when ready, or creating a 'ready' file).

Consider using something more 'data push' such as RMI, HTTP-POST, JMS queues, etc.

Martin Cowie
+4  A: 

A thread is interrupted when it is blocking (the call to sleep) and another thread calls its interrupt method. The call to interrupt must be made explicitly for this to happen.

Seems that repeating the check for the file would be the logical thing to do if the thread is interrupted, but without knowing the cause of the interruption it's hard to say.

As usual, when it comes to threading, Brian Goetz has something to say on the matter of InterruptedException:

http://www-128.ibm.com/developerworks/java/library/j-jtp05236.html

Nick Holt
A: 

If all you want is a notification when a file is created, AND you can (and willing) to go native (JNI) AND you want only win32 support, you could use the code here.

Ran Biron
yes, i need only to be notified when the file is created. i see the code attached but i don't understand what is the notify filter? can u tell me please
it's c++ code you're supposed to compile to a dll, then access via JNI (java native interface). it's not platform independent and has other restrictions, and JNI is quite slow going through the interface, but it works perfectly.
Ran Biron
Link broken....
Thorbjørn Ravn Andersen
A: 

Well, if you don't know what InterruptedException is and/or don't want to do anything about it, obviously you should at least do something besides returning and exiting your loop. Take out the return, and then you'll keep waiting.

But I'd check into why you're getting interrupted. Something is trying to cancel your thread.

skiphoppy