• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads writing multiple files in a directory

 
Abhilesh Khatri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am working ona application, where in i use threads to write reports. I need to write about 8 html files into a single directory.
I spawn eight threads one each for each report. At the time of writing the file i am getting "Access Denied Exception"
I guess the problem could be thread might be locking the directory making it unavailable for other threads to write its corresponding reports in the same directory.
For the time being i am using join() on the threads which makes them to que one after the other.
This is leading to performance issue. Each threads takes an average of 3 minutes to writ the html file. Now for the 8 report it is consuming 25 minutes.
If i can solve the access denied exception and make the threads write in the same directoru simultaneously it may take less than 5 minutes, which is what we desire.

Is this a limitation on the part of the threads? Or is there awork around for this issue?
Thanks in advance for all your inputs
abhilesh
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a limitation of threads. I've had multiple threads write to multiple fies in the same directory without any problems. I think the problem lies elseware. Post code.
 
Abhilesh Khatri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[Added [code] tags for readability & reformatted overlong lines - Jim]
[ January 07, 2003: Message edited by: Jim Yingst ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the exact text of the error message you see? And point out which line in your code it refers to, since we can't tell line numbers from the code you posted.
It occurs to me that there might be something platform-dependant here. Try running the following test code on your system to verify that it can write ten HTML files simultaneously. If this works, modify the code to put the files in the same directory you're currently trying to write to in your real code, and try again.
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the line number will help. Also, this code:
reportDir.mkdirs();
Is called by all the threads without being synchronized. Without know ing the line that throws the exception this is a wag, but that might be the problem.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a seperate note, this is redundant:

If you're going to start one thread at a time and wait for it, you might as well just call run() directly and avoid the overhead of creating more threads.
I don't think that's what you want to do, though. You want to run ten threads simultaniously. For that you would have to start() all the threads before you call join() on any of them. The basically means calling join() in a separate loop.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhilesh noted the use of join() in the first post. It sounds like this is a temporary hack to get the code to write files without the access exception. I assume if he can get rid of the access problem, he will remove the join() command.
 
Abhilesh Khatri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all your inputs.
As pointed out, the problem was with
" reportDir.mkdirs(); ".
I removed this and added code that creates directory only when the directory is not there. With this the access probelm has been solved.
Thanks agian for all your inputs and feed back
ABhilesh
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhilesh Khatri:
Thanks a lot for all your inputs.
As pointed out, the problem was with
" reportDir.mkdirs(); ".
I removed this and added code that creates directory only when the directory is not there. With this the access probelm has been solved.
Thanks agian for all your inputs and feed back
ABhilesh

Damn I'm good. :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!