Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple threads for directory creating  RSS feed

 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I synchronize the directory creating,when multiple threads try to create the directory and its sub directory.


I try to change existing code to multiple threads. It throws exception of "Failed to create directory" as there are about 10 threads will try to create the directory "XML" or "XML/publish" , I try to add synchronized(tester) for if clause, but it doesn't work.


Thanks a lot for your advice.


exportDir can be XML or XML/subdir
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that sychronized(tester) should work provided that the tester object is the same object used by each thread. In your code snippet, you show tester being instantiated - does this happen for each thread? Make sure you're using the same tester object to synchronize on or chose another object to synchronize on that is within scope of all threads.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!