aspose file tools*
The moose likes Threads and Synchronization and the fly likes Threaded File Checker Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threaded File Checker" Watch "Threaded File Checker" New topic
Author

Threaded File Checker

Mark Mero
Greenhorn

Joined: Oct 14, 2004
Posts: 12
I am looking to create a file checker that will check the availability of multiple files. I want this to be threaded so that multiple files can be checked for at the same time.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
To run a task on multiple threads, encapsulate the task code in its own class. Make the task class implement Runnable and put the task code in the run() method. Then you can do something like this:

I'll let you work out Task ... the run() method contains the file check code and saves the result in a member variable.

That's real sketchy ... is it enough to go on?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Mark Mero:
I am looking to create a file checker that will check the availability of multiple files. I want this to be threaded so that multiple files can be checked for at the same time.


Forgive me if you have already looked into this issue, but it seems to me that this might not be a good application for multi-threading. If all the files are on the same file system, then checking for lots of files "all at once" may not achieve improved performance.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Mark Mero
Greenhorn

Joined: Oct 14, 2004
Posts: 12
Sorry if i didn't explain myself very well.

The thread will target a file checking class that will loop through the file definitions until all files have been received.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The logic I showed above would do the trick if each task looped inside its run method until the file existed. But it would be overkill. You don't need a thread per file, just one thread for the checker. Here's a possibility not quite in Java ...

At any moment the collection contains a list of files not yet found if anybody else is interested. You might have to synchronize any get on the remaining list.
 
 
subject: Threaded File Checker