Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One file should be processed by one thread

 
aresh babu
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Use a thread pool to allocate unique files for each thread.

Thanks
Sachin CR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic