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 6085319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:37:33+00:00 2026-05-23T11:37:33+00:00

I have a problem with a timer in my logger class. I created my

  • 0

I have a problem with a timer in my logger class. I created my own logger which should be as simple as it is possible – user can only call static log() method. Every call log() method causes that a log object (message, time, additional information) is adding to a list of logs.
When user calls this method first time, logger also starts a new Timer which saves all logs from a list to a file every 30seconds.

However, I don’t have any idea where to call timer.cancel() method. I don’t want to force user to do this in his code. Is it necessary to always cancel timer? Or this method is just to stop when user wants it.

  • 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-05-23T11:37:33+00:00Added an answer on May 23, 2026 at 11:37 am

    But you do not need shutdown hook at all in this case. When VM is closed, all the threads will be cancelled anyway, and all open files will be closed, so no worries.

    I believe what you want is to avoid the task waking continuously every 30 s even if app is not doing anything. I propose to do it a bit differently:

    Whenever you log something in log method:

    • store log entry
    • check if you have a timer task waiting to be executed (one boolean volatile ‘taskRunning’ flag). If not – fire task with 30 seconds delay, but only ONCE (not repetitive) and set the taskRunning flag to true. If flag is set to true – do nothing.
    • in your timer task: clear the ‘taskRunning’ flag, write all the logs stored so far and … do not fire another task. No need. Whenever someone writes log file, it will start another task which will write logs 30 secs after.

    Note. In order to avoid races you need some synchronisation on log read/write as well.

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

Sidebar

Related Questions

I have spent some time now to solve a problem for which i have
I have created simple example with @Singleton, @Schedule and @Timeout annotations to try if
Here is my custom logger class, which helps me create logs file in my
I'll just get right into it. I have a class User that needs to
I have a problem with authorized SSL connection. I have created Struts Action that
I have a class for logging, which MUST NOT inherit std::ostream, and has operator<<
I have a ViewController that contains a UITableView in which the cells are created
I have this : class Stress def initialize(user, pass) @user = user @pass =
I have created a simple WordPress page template. I am working on live server.
I have a problem with time My server is in the USA and I'm

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.