Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multithreaded XML file parsing?



On Aug 19, 2006, at 7:14 PM, Saad Mahamood wrote:

Some followup responses:

In the end I did go ahead a use just a single threaded instance
parsing the XML file using SAX, and the performance was much better
than I had initially expected. However I have a follow question:

One area in my code that could benefit from threading is the following:

File[] dirChildren = gmlDir.listFiles(filter);
       for(File aFile : dirChildren) {
           System.out.println("Got here!");
           //Iterate through the list of files and start loading GML files:
           GMLThread thread =  new GMLThread(aFile);
           thread.run();
           try {
               thread.join();
           }
           catch(InterruptedException ie) {
               ie.printStackTrace();
           }
           System.out.println("Got here! 2");
       }


I'm not loading one XML file, but several in a directory. However, I
can't figure out how to iterate through the File arraylist and start
several parsing threads, whilst making the main application thread
wait until they've have all completed? The current code above only
makes the "for each" loop wait until the thread its spawned has
completed, which isn't the behaviour I want.

Saad,

Create an array of Thread objects.
Have one for() loop that starts each Thread. This will get each thread running in the background.
Have a second for() loop that joins each Thread. This loop will exit when all threads have completed.

One warning on this: this means that you will have all of your XML files in memory at once. Perhaps this is what you want, but if you aren't expecting this, you could end up eating a lot of memory (depending of course on the size of your XML files).

Rick
--
Rick Genter



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Multithreaded XML file parsing? (From: "Saad Mahamood" <email@hidden>)
 >Re: Multithreaded XML file parsing? (From: Oisin Hurley <email@hidden>)
 >Re: Re: Multithreaded XML file parsing? (From: "Saad Mahamood" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.