Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / March 2006

Tip: Looking for answers? Try searching our database.

Problem with java.io.File and Multi - Threads

Thread view: 
Vishal - 05 Mar 2006 06:54 GMT
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
Roedy Green - 05 Mar 2006 07:40 GMT
>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?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Vishal - 07 Mar 2006 04:17 GMT
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
Roedy Green - 07 Mar 2006 07:10 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Oliver Wong - 07 Mar 2006 19:20 GMT
> Hi Roeby,
>
[quoted text clipped - 11 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.