Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:03:47+00:00 2026-06-01T21:03:47+00:00

In Java util logging, I initiate the handler on init(), and close the handler

  • 0

In Java util logging, I initiate the handler on init(), and close the handler at destroy() and it works perfectly fine: A log file was created, etc. If the user refreshs the page normally, it still just creates one log file.

However if the user refreshs the page with the applet a couple of times fast, it seems like the destroy() does not get called or maybe hasn’t finished the task and since the init() gets called again, it assumes the previous file is still locked and creates a new log file.

I tried to use both destroy() and finalize() to close the handler but it does not work.
Anyone has any idea how to solve this issue?

Another minor question is: What actually happened if init() has not finished and the page gets refreshed. Is it going to continue the process and eventually failes to call destroy() or does it just stop right there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:03:48+00:00Added an answer on June 1, 2026 at 9:03 pm

    Quote from Java Tutorials:

    The Java Plug-in software creates a worker thread for every Java
    applet .

    In multithreaded environment you should be very careful with shared resources. Best and easiest approach is not to share anything (scales best and no deadlocks possible).

    I assume, that you initialize your handler each time in "init"-method. If it’s true, you should use one static shared logger (check this link). It will help to improve situation a bit, but if you start more than one browser with your applet – new log file still will be created. And this workaround is not recommended by Oracle and preserved for backward compatibility.


    Recommended and easy to implement solution – "each applet should have it’s own logger and write to own file". Code for log file name generation:

    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    
    private String generateFileName() {
        return String.format("applets-log/%s-%s.log", dateFormat.format(new Date()), UUID.randomUUID());
    }
    

    Also, Best Practices For Applet Development.


    Answer to your minor question (changed):

    According to discussion of this old bug in java plugin, applet could be terminated at any moment with some predefined interval for cleanup. So you should put resource cleanup code in your "stop" or "destroy" method, but you shouldn’t rely what that code will be executed.

    Applets lifecycle is controlled by browser and applets should not be
    given capabilities to run when its hosting document is destroyed by
    browser.

    Since 6u10, both old plugin and new plugin enforce applet shutdown
    after a fixed amount of time (1000ms in old plugin and 200ms in new
    plugin) for applet to stop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I currently have this in my .properties file: java.util.logging.FileHandler.pattern = %h/programName%u%g.log I would
is it possible to use java.util.Logging and log to a file in a java
I am using java.util.logging.Logger But with storing messages in a log file, it also
For debugging purposes, I would like my app to log to a java.util.logging.SocketHandler. Here's,
java.util.logging.Logger override (overwrites) the file data instead of add to end of file. Is
I'm using Tomcat 6, and this is my logging.properties: handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler .level=FINE
Using java.util.logging.Logger to output some log to the console just like this: public static
I'm currently writing an own java.util.logging.Handler , and I dont really understand the concept
I want simply to log on the console using java.util.Logging: Logger log = Logger.getLogger(my.logger);
Is java.util.logging.Logger.log() is a chain of responsibility pattern?If so how log method call is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.