dcsimg
How do I read a directory of text files quicker using threads.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ganan_Sri
Posted On:   Wednesday, March 13, 2002 04:53 AM

I have a directory of xml files, which I just read into a vector, using normal methods.
However the files are large, so it takes ages to read all the files into the vector.
Is there a quicker way?

Re: How do I read a directory of text files quicker using threads.

Posted By:   Christopher_Schultz  
Posted On:   Wednesday, March 13, 2002 05:57 AM

I'm note sure if it will help, since there's so much IO involved, and to too much processing, but you could try this:





class XMLFileReader
implements Runnable
{
Vector _vector;
String _filename;

public XMLFileReader(String filename, Vector v)
{
_filename = filename;
_vector = v;
}

public void run()
{
// open and parse _filename

_vector.add(...);
}
}



In your main program:




Vector vector = new Vector();

foreach filename in filenames
{
new Thread(new XMLFileReader(filename, vector)).start();
}



You might have to keep a reference to those threads around, so that you can join them to make sure all the files are loaded before you continue processing.



Good luck,

-chris
About | Sitemap | Contact