Thursday 15 March 2012

java - Monitoring directory for changes from web service -


Do not know if this is clear from the title, I will explain it deeply.

First of all the borders: Java 1.5 IBM.

This is the situation:

I have a Spring Web service, in which the request is received with a PDF document. I need to put this PDF in some Input directory which monitors the AFP application (not important). This AFP application takes that PDF, does something with it and returns it to some Output directory which I need to monitor. Monitoring the output directory will take some time, probably 30 seconds Apart from this, I know what is the exact file name that I expect to appear in the output directory, if some mistake reacts back then nothing appears in 30 seconds.

Because of my poor knowledge of web services and multithreading, I do not know what potential problems I can face In addition, for the search of the Internet, I know that most people watch for the Monitor , But it has been introduced in Java 7. Any suggestions, links, ideas will be helpful.

So, the scenario is simple. In one main method, the following actions are done in order:

  • Call the AFP service;
  • Select the directory for the output file;
  • Deal with the output file.

    We believe that outputFile is a file that contains the full path to the file generated; This method returns zero , optimize:

      // we vote every second, so ... the personal stable final interval SAMPLES = 30; The APP (whatever, the arguments are, there are) with the public zero deal, whichever is necessary {callAfpService (here); Int i = 0; Try {while (i & lt; sample) {TimeUnit.SECONDS.sleep (1); Break if (outputFile.exists ()); } New which is required (); } Grab it (interrupted e) e. {// Method to throw it back, otherwise at least: thread. Concert (). Interrupt (); New which is required (); } DealWithOutputFile (outputFile); }    

No comments:

Post a Comment