AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with java.io.File and Multi - Threads

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Software Tools
View previous topic :: View next topic  
Author Message
Vishal
Guest





PostPosted: Sun Mar 05, 2006 7:12 am    Post subject: Problem with java.io.File and Multi - Threads Reply with quote



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





PostPosted: Sun Mar 05, 2006 8:12 am    Post subject: Re: Problem with java.io.File and Multi - Threads Reply with quote



On 4 Mar 2006 22:54:12 -0800, "Vishal" <vdedaniya (AT) gmail (DOT) com> wrote,
quoted or indirectly quoted someone who said :

Quote:
removeFiles()

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





PostPosted: Tue Mar 07, 2006 5:12 am    Post subject: Re: Problem with java.io.File and Multi - Threads Reply with 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. ;)

Thanks,
vISHAL
Back to top
Roedy Green
Guest





PostPosted: Tue Mar 07, 2006 7:12 am    Post subject: Re: Problem with java.io.File and Multi - Threads Reply with quote

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. Wink

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





PostPosted: Tue Mar 07, 2006 8:12 pm    Post subject: Re: Problem with java.io.File and Multi - Threads Reply with quote

"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. Wink

"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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Software Tools All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.