It's not a secret anymore!*
The moose likes Threads and Synchronization and the fly likes One file should be processed by one thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "One file should be processed by one thread" Watch "One file should be processed by one thread" New topic
Author

One file should be processed by one thread

aresh babu
Ranch Hand

Joined: Aug 31, 2008
Posts: 65
Hi,

i have a requirement that is..

I have 2 text files and 2 threads in my porgram. My task is i need to allow only one thread to execute a one file. If thread1 executed the first text file then thread2 is not supposed to execute the first text file because it is already processed by first thread but at the same time thread2 is supposed to execute the second text file if the file is not processed by first thread. In the same way if second text file is already proccessed by thread2 then thread1 is not supposed to process the second text file.

Finally what i want to do is,
i want to process a one text file with one thread, if the text file is already processed by the first thread then second thread is not supposed to process the file, whatever the files are left out by the thread1 that files are only supposed to process by the thread2.

Can any one please let me know how to achieve it???


Thanks in advance
Aresh Babu
Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
A general solution would be to set up a queue for the file names, and a thread pool to process the files, but it may be an overkill for your problem. It'd allow you to process any number of files with any number of threads.
Sachin Chandra
Greenhorn

Joined: Jun 19, 2009
Posts: 7
Hi,
Use a thread pool to allocate unique files for each thread.

Thanks
Sachin CR
 
wood burning stoves
 
subject: One file should be processed by one thread