The moose likes Applets and the fly likes Destroy method of Applet... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Destroy method of Applet..." Watch "Destroy method of Applet..." New topic

Destroy method of Applet...

Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Is the destroy method called only at the time of browser close? I am using a buffered reader for my applet. I need to close the buffer at the end, when I close the buffer in the destroy method it gets closed after the applet is loaded completely. For further usages I am not able to access the buffered reader. How to close the buffer when the browser is closed or when the user navigates to some other page.


Ananth Chellathurai [Walk on software]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
What kind of Reader is this, and why does it need to be kept open? The most natural thing to do would be to close the Reader when you're done with it.

To investigate the applet lifecycle you should write a little applet that prints messages to System.out whenever one of its lifecycle methods is called (init, start, stop, destroy). Then you'll get a feeling what code might go into which method. Also, not all browsers/JVMs are fully consistent as to when they call these methods.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Thanks Ulf.

I found that buffered reader cannot be re used. I gave a System.out in destroy method, and I found it is getting printed after every time the page load is complete. Now I am closing the buffered reader after use, and going to a servlet again to get the buffered reader when needed.

Thanks buddy
subject: Destroy method of Applet...
jQuery in Action, 3rd edition