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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:29:54+00:00 2026-05-29T22:29:54+00:00

I have a long-lived server application that is designed to run with minimal downtime

  • 0

I have a long-lived server application that is designed to run with minimal downtime (e.g. 24/7 operation stopping only for maintenance). The application has to be able to handle thousands of requests a second, so performance is a concern.

To service each request. part of the application needs to know what the current date is (although not the time) and it must be stored in a java.util.Date object because of a 3rd party API.

However,Date objects are expensive to construct so creating a new one for each request doesn’t sound sensible.

Sharing a Date object between requests and updating it once a day would mean only a single object would need to be created (per server worker thread) at startup, but then how can you update it in a safe manner?

For example, using a ScheduledExecutorService that runs just after midnight could increment the Date, but introduces Thread synchronisation into the mix: the Date object is now shared between the main thread and the thread that the ScheduledExecutorService spawns to run the update task.

Synchronising the 2 threads introduces another performance headache, due to the likelihood of contention on the shared resource between the thousands of requests being serviced (the single execution of the update thread per day is less of a concern because it only happens once per day, unlike the millions of requests we will service daily).

So, my question is What is the most efficient way to ensure the application always knows what the current date is, even when running continuously for weeks on end?

  • 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-29T22:29:55+00:00Added an answer on May 29, 2026 at 10:29 pm

    @chrisbunney, a couple of the answers on this thread have suggested using special-purpose concurrency classes, but if you really did need to cache a date as you originally asked, there’s only one thing you need: the volatile keyword.

    AtomicReference is good if you need an atomic check-and-swap operation, but in this case, you’re not checking anything. You’re just setting a reference to a new value, and you want that value to be visible to all threads. That’s what volatile does.

    If you were modifying the internal state of an existing object, then you might need locks. Or if you were going to read the value of the existing Date, do some calculations based on that, and generate a new Date object as a result, again some type of locking (or something like AtomicReference) would be necessary. But you’re not doing that; again, you’re only replacing a reference, with no regard to its previous value.

    In general, if you have only one thread which ever replaces a value, and other threads only read the value, volatile is enough. No other concurrency control is needed. Or if you have multiple threads which can replace a value, but they only replace, not modify in-place, and they replace it with no regard for its previous value, then again, volatile is enough. Nothing else is needed.

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

Sidebar

Related Questions

We have a long-lived ASP.NET 3.5 application we are moving from a physical server
I have a python app which is supposed to be very long-lived, but sometimes
I have long tables generated by datagrid control that go beyond the page width.
I have long recognized that any set of whitespace in an HTML file will
I have long been of the opinion that the time and resources it would
I have a ASP.NET Web Forms application that internally makes many SOAP and REST
I am trying to establish a long lived connection using jQuery. I have a
I've inherited a Winforms application that does a lot of long running calls into
I have a .net 3.5 application running on windows mobile professional that uses sql
I have a .NET 2.0 server that seems to be running into scaling problems,

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.