Auto detection

Hello,

I have a java application that takes the name of a file as a command line argument and then works on it. My new requirement is to make the application more responsive in that it should automatically detect the file if it is dropped into a folder. The system is running on windows XP.

So in essence,

The java application should detect the new file, extract the file name and work on it.

Any suggestions and ideas would be really appreciated.

Many thanks

[498 byte] By [Lexus316a] at [2007-11-26 16:03:47]
# 1
you need a thread running that continuosly checks the target directory for new files appearing. there isn't a FileListener or anything handy, nor is there any native code that will do this on most platforms (BeOS is an exception, but the JVM for BeOS is somewhat lacking, apparently)
georgemca at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 2
http://onesearch.sun.com/search/onesearch/index.jsp?qt=file+listener&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums
CeciNEstPasUnProgrammeura at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 3
You can create a schedule job (windows) that calls a Java program from time to time to check if a new file is there (checking it's date for instance or creating a control file). I think this approach is better than having a thread continuously.regards,Manuel Leiria
manuel.leiriaa at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks for the replies guys
Lexus316a at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 5
Manuel,I didnt quite follow what you were saying. Could you elaborate plz?
Lexus316a at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 6

> You can create a schedule job (windows) that calls a

> Java program from time to time to check if a new file

> is there (checking it's date for instance or creating

> a control file). I think this approach is better than

> having a thread continuously.

>

> regards,

>

> Manuel Leiria

possibly a better approach, yes.

this of course couples you to the platform but in reality that's rarely the problem people think it will be. but there are other reasons not to use scheduled tasks, cron jobs etc, for instance, if you want to monitor and manage the jobs through java. another consideration is how often the java code will come into play. there's little point closing down and re-starting JVMs every few seconds, the expense is too great. may as well just leave a thread running

georgemca at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 7
The current requirement is to run the app once an hour. This interval could increase but there is zero to little chance that it would decrease.
Lexus316a at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 8
> The current requirement is to run the app once an> hour. This interval could increase but there is zero> to little chance that it would decrease.how long does a run take? a scheduled task or cron job might be better, but it involves extra management
georgemca at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 9
All this app does it to read the file, act on the contents and generate an output file. So the whole process will take about 9-10 seconds max.
Lexus316a at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...
# 10

> Manuel,

>

> I didnt quite follow what you were saying. Could you

> elaborate plz?

In Windows -> Control Panel you have something called Scheduled Tasks where you can assign a program and tell at what times it should be executed, so, create a task to call your Java program from hour to hour.

regards,

Manuel Leiria

manuel.leiriaa at 2007-7-8 22:25:41 > top of Java-index,Java Essentials,Java Programming...