Directory listing using threads

Hi,

I have a requirement to list the files under all the directories.i dont want to do a simple listfiles()(File API) as it would take lot of time since there are million files.I would like to use some threading where in each thread can take up a directory and list the files .something like this..

Not that every directory to have a single thread but spawn many threads and make that thread display the directory contents and reuse the thread for other directories.

Can someone throw some light on the code.

Thanks very much

[556 byte] By [mort2007a] at [2007-11-27 1:30:56]
# 1

> Hi,

> I have a requirement to list the files under all the

> directories.i dont want to do a simple

> listfiles()(File API) as it would take lot of time

> since there are million files.I would like to use

> some threading where in each thread can take up a

> directory and list the files .something like this..

> Not that every directory to have a single thread but

> spawn many threads and make that thread display the

> directory contents and reuse the thread for other

> directories.

Using separate threads for each directory will NOT make the app go faster.

In fact, it will be much, much slower since they will be competing for disk access.

(On a modern disk drive, the seek time is orders of magnitude slower than read time)

Instead, look at how Windows Explorer does it.

When you browse a large directory, it first shows an empty folder.

It then spawns a separate thread to populate the folder with the filenames...

And if that's done, the thread then queries and displays the icons of each file.

But! Here is the crucial difference.

This new thread is interruptible.

So when you click on a different dir, the old thread is killed,

and a new thread is started that tries to query the icons in the new directory.

Interruptibility is the key. Not creating 1000 threads for 1000 directories.

Edit:

I'm assuming here that you are talking about a GUI.

Because if you're talking about a commandline app, and that

you MUST display all 1 million files, then going sequentially is

much faster than using multithreading.

KathyMcDonnella at 2007-7-12 0:32:53 > top of Java-index,Core,Core APIs...