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
posted 12 years ago
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.