 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Vishal Guest
|
Posted: Sun Mar 05, 2006 7:12 am Post subject: Problem with java.io.File and Multi - Threads |
|
|
Hi everyone,
I am having a problem with the java.io.File.delete() method while
calling my function and running multiple threads within it. I have
written a function which is going to remove a file in a directory. This
function works well when a single thread executes it. But causes
problems in multi-threaded environment. Each thread creates a new
object and calls the removeFiles()
method in its object. Each thread is trying to delete a file in its own
directory, but delete() call seems to work for some of the threads but
fails for others.
Please help..
Thank in advance
vISHAL |
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sun Mar 05, 2006 8:12 am Post subject: Re: Problem with java.io.File and Multi - Threads |
|
|
On 4 Mar 2006 22:54:12 -0800, "Vishal" <vdedaniya (AT) gmail (DOT) com> wrote,
quoted or indirectly quoted someone who said :
the basic method is called File.delete. What is removeFiles?
Is the problem you are deleting an already deleted file? or one you
have open on another thread?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching. |
|
| Back to top |
|
 |
Vishal Guest
|
Posted: Tue Mar 07, 2006 5:12 am Post subject: Re: Problem with java.io.File and Multi - Threads |
|
|
Hi Roeby,
removeFiles() is user define function name, which is internally calling
File.delete() method only.
No, i am not deleting an already deleted file.
No, each threads has diff files, so there is no questions of locking
and all.
Thanks for your reply.... but i got solution for these issues.
When i called System.gc() before deleting any files then its working
fine for me. I don't know the logical reason but now its working fine
for me. ;)
Thanks,
vISHAL |
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Mar 07, 2006 7:12 am Post subject: Re: Problem with java.io.File and Multi - Threads |
|
|
On 6 Mar 2006 20:17:43 -0800, "Vishal" <vdedaniya (AT) gmail (DOT) com> wrote,
quoted or indirectly quoted someone who said :
| Quote: | When i called System.gc() before deleting any files then its working
fine for me. I don't know the logical reason but now its working fine
for me.
|
If you can get this to work in a sample small program, I'm sure sun
would like to see it. I can't think of anything you could
legitimately do that would cause this behaviour. It sounds like
Sun/MS's bug.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching. |
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Tue Mar 07, 2006 8:12 pm Post subject: Re: Problem with java.io.File and Multi - Threads |
|
|
"Vishal" <vdedaniya (AT) gmail (DOT) com> wrote in message
news:1141705063.585423.224600 (AT) z34g2000cwc (DOT) googlegroups.com...
| Quote: | Hi Roeby,
removeFiles() is user define function name, which is internally calling
File.delete() method only.
No, i am not deleting an already deleted file.
No, each threads has diff files, so there is no questions of locking
and all.
Thanks for your reply.... but i got solution for these issues.
When i called System.gc() before deleting any files then its working
fine for me. I don't know the logical reason but now its working fine
for me.
|
"I don't know why, but it's working now, so let's ignore it" is an okay
strategy for single threaded programs, but can lead to big problems for
multithreaded programs. I advise you to investigate further.
- Oliver |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|