This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
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
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.<br /> <br />#:^P
Mark Mero
Greenhorn
Joined: Oct 14, 2004
Posts: 12
posted
0
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
posted
0
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.