File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes applet within browser not releasing file resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "applet within browser not releasing file resource" Watch "applet within browser not releasing file resource" New topic
Author

applet within browser not releasing file resource

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

hi all,

I have an applet for ftp images upload using a third party ftp API library (edtftpj).

run from eclipse IDE (which uses applet viewer) the applet is doing the upload task perfectly.
if i run my applet from browser here is what happens:

i upload a file & leave the browser opened.
i then open this same file with gimp or photo-shop & get 'file in use' error.

if i close browser & try opening file ,the file is opened ok.
I'm sure i don't open any streams inmy applet & also the ftp library close their streams & have no bugs .I'm only using java File Objects & these ones doesn't need to be closed or disposed in someway. am i right ?

why the file isn't released when applet instance still on browser ?
i hope someone could help on this .

thanks .
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Originally posted by othman El Moulat:
hi all,

I have an applet for ftp images upload using a third party ftp API library (edtftpj).

run from eclipse IDE (which uses applet viewer) the applet is doing the upload task perfectly.
if i run my applet from browser here is what happens:

i upload a file & leave the browser opened.
i then open this same file with gimp or photo-shop & get 'file in use' error.

if i close browser & try opening file ,the file is opened ok.
I'm sure i don't open any streams inmy applet & also the ftp library close their streams & have no bugs .I'm only using java File Objects & these ones doesn't need to be closed or disposed in someway. am i right ?

why the file isn't released when applet instance still on browser ?
i hope someone could help on this .

thanks .


First, let's get the obvious parts out of the way. You're in development now, so maybe you're testing all this on one machine. After the "upload", there are two files: the original one, and a new one. We're talking about opening the original one in the GIMP, not the new one, right?

Now, as to "the ftp library close their streams & have no bugs": remember that if something inexplicable happens, then one of your assumptions is false. This one seems the most likely to be false, as it's the hardest to confirm. Make sure you're using the library properly; consult their support resources, if any.


[Jess in Action][AskingGoodQuestions]
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Originally posted by Ernest Friedman-Hill:


First, let's get the obvious parts out of the way. You're in development now, so maybe you're testing all this on one machine. After the "upload", there are two files: the original one, and a new one. We're talking about opening the original one in the GIMP, not the new one, right?

Now, as to "the ftp library close their streams & have no bugs": remember that if something inexplicable happens, then one of your assumptions is false. This one seems the most likely to be false, as it's the hardest to confirm. Make sure you're using the library properly; consult their support resources, if any.


thanks for reply.

we are now testing on production stage.the files are uploaded to a remote ftp server from local drives of user's machines.i don't think it's the issue of 2 files existing in same machine at same time.
we asked edtftpj team and we are sure it's not an issue with the library.we have this same issue in another applet which don't use this library.
i went through the code to make sure if i missed some stream opened .all seems ok.
one thing important is that if i run applet in eclipse IDE i don't get this problem.so i suspect it to be a permission access issue or something like that.(we are signing our applet.)
any other ideas what could be the problem ?

thanks.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

I investigated the issue more thoroughly and here are my conclusions :

1) First i made sure to close all File's streams in the applet.so I'm sure i eliminated this issue of forgotten opened file streams .
2) also i made sure to close all network connections that might be holding the File lock.

It's clear that another process is still locking the File & preventing access to it.
i used a win32 program (procExp) to monitor active processes . it turned out that javaw.exe is the process that use the File. i was convinced of this fact with a simple experiment : if i destroy the applet (closing applet's browser window -not necessarily all browser instances-) then in this case the file lock is released and i can access and delete File correctly.

the conclusion : How to instruct javaw.exe to release the File lock ?
is it a bug in JVM ? (i'm using jdk1.4.4)
or is it an OS centric issue related to windows only ?

i would appreciate your ideas about this problem .

thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
This sounds odd indeed. Make sure that the File object becomes eligible for GC. You might want to try this with different JVMs (Sun 1.5 and IBM), and possibly on different operating systems (OS X and Linux).


Ping & DNS - updated with new look and Ping home screen widget
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thank you for your interest in my issue.

I made sure to call System.gc() before trying to delete the File but still same problem.
i use Firefox browser & IE 6 with java 6 plugin .but my applet classes are compiled with jdk 1.4.2.
i also tried my applet in apple mac & get same problem.however i didn't tried it yet on Linux .

I'm still suspecting that javaw.exe process is responsible for Locking the file.could this be true ? if yes why this is happening ? it should not be allowed as this will be a real limitation for applets.
i know this seems odd .I'm really experiencing hard times to figure out this problem.

can you help guys ? i would appreciate it a lot.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi,
let me explain more the situation in the applet :

if i cancel a ftp upload i can delete the partially uploaded file .(indeed i had to quit() & reconnect before being able to delete ftp file).

however i'm facing a hard time to do same with file download:
if i cancel ftp download & try to delete partial file on local drive the File.delete() method fails.
it seems some other process (maybe javaw.exe or the Thread i use for download) is locking the file.
before calling File.delete() i call Thread.interrupt() to stop download thread. i also set my thread object to null and call System.gc() before trying delete() .but still unable to delete the partial downloaded file.

any Ideas ? thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
Calling System.gc() may or may not do anything, and is in any case not the same as making the File object eligible for GC. For that, the object must be unreachable; in other words, no reference to it must be stored anywhere. Is that the case?
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Originally posted by Ulf Dittmer:
Calling System.gc() may or may not do anything, and is in any case not the same as making the File object eligible for GC. For that, the object must be unreachable; in other words, no reference to it must be stored anywhere. Is that the case?


I store a reference to the file path String.when i want to delete file i create it :


this doesn't work .what you suggest ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
What does the delete method return? Are there any exceptions?
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Originally posted by Ulf Dittmer:
What does the delete method return? Are there any exceptions?


returns false .there are no exceptions .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet within browser not releasing file resource
 
Similar Threads
Regarding FTP froma remote server
FTP Upload
a file in your Jar, How do I access it in code?
Hide a URL: Example (Download THIS File)
browser running in background