[concurrency-interest] Help

David Holmes davidcholmes at aapt.net.au
Mon Jan 23 17:40:18 EST 2012


This is off-topic for this list.

David
  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Dr Heinz M. Kabutz
  Sent: Tuesday, 24 January 2012 6:12 AM
  To: edsen at libero.it
  Cc: concurrency-interest at cs.oswego.edu
  Subject: Re: [concurrency-interest] Help


  Does "Strings.setDateTimeFromFileName" by any chance use java.util.SimpleDateFormat stored in a static field?

  Otherwise, could you please send us some working code that we can run in order to see the effect you are talking about?

Regards

Heinz
-- 
Dr Heinz M. Kabutz (PhD CompSci)
Author of "The Java(tm) Specialists' Newsletter"
Sun Java Champion
IEEE Certified Software Development Professional
http://www.javaspecialists.eu
Tel: +30 69 72 850 460
Skype: kabutz 


  On 1/23/12 10:31 AM, edsen at libero.it wrote: 
    Hello,



    I need orders my files from list directory, that is changing continously.

    My files must be fetched by order-date (oldest from newest...) and I check the age of files from file naming convention. The files are:XXXXX_yymmdd.

    Below you can find the code that get the following input parameters: 



    - this.directory: directory of file list.

    - fileRegexp: regular expression in order to retrieve the date.

    - datetimeGroup: group where the date is present in the file naming convention.

    - timestampFromFileNameFormat: date format convention.




    // get the list of files currently in the directory



    File[] files = 

    this.dirListByDate(this.directory,fileRegexp,datetimeGroup,timestampFromFileNameFormat);








    protected  File[] dirListByDate(final File folder, final Pattern fileRegexp, final int datetimeGroup, final String timestampFromFileNameFormat) throws IOException {



    if  (!folder.isDirectory() || !folder.exists()) {

    throw new

    IOException(folder.getName() +  " : Not a folder or not exist");

    }



    File files[] = this.list(folder, false); 

    // don't include subfolder

    Arrays.sort(files, newComparator<Object>() {

    public int compare(final Object o1, final Object o2) {



    final String s1 = ((File) o1).getName();

    final String s2 = ((File) o2).getName();

    final  Matcher m = fileRegexp.matcher(s1);

    final  Matcher n = fileRegexp.matcher(s2);



    if  (m.matches() && n.matches()) {

    final String date1 = m.group(datetimeGroup);

    final String date2 = n.group(datetimeGroup);

    final long dateAndTime1 = Strings.setDateTimeFromFileName(date1, timestampFromFileNameFormat);

    final long dateAndTime2 = Strings.setDateTimeFromFileName(date2, timestampFromFileNameFormat);



    return dateAndTime1 < dateAndTime2 ? -1 : dateAndTime1 > dateAndTime2 ? 1 : 0;

    }

    else

    {

    log.error("Files don't match...File1->" + s1 + " File2 -> " + s2);

    alarm.sendAlarm(AlarmInterface.FILE_NAMING_CONVENTION_FAILED,"File Naming Convention incorrect: "

    +

    s1 + 

    " with size " + s1.getBytes() + " of directory " + folder + s2 + 

    " with size " + s2.getBytes() + " of directory "+ folder);

    return 0;

    }

    }

    });

    return files;








    protected File[] list(File folder, boolean includeSubFolder) {



    if  (!folder.isDirectory()) {

    return null;

    }



    File files[] = folder.listFiles();

    List<File> list = new ArrayList<File>();



    for (File file : files) {



    if  (file.isDirectory()) {

    if (includeSubFolder) {

    list.add(file); 

      }

    } 

    else

    {

    list.add(file);

    }

    }



    if(list.isEmpty()) {

    return list.toArray(newFile[] {});

    }

    return list.toArray(new File[] {});

    }



    What happens? Happens that every thing works for 3-4 traffic days, but sometimes it processes newest files instead of oldest.

    I don't understand what can be wrong??

    Can you help me in order to fix it?

    Can you suggest me a solution?



    Thanks in advance.

    Kind regards.









----------------------------------------------------------------------------
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120124/28e96883/attachment.html>


More information about the Concurrency-interest mailing list