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

  • Home
  • SEARCH
  • 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 8484013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:15:54+00:00 2026-06-10T20:15:54+00:00

In my Java webapp, each instance is checking on startup if the database is

  • 0

In my Java webapp, each instance is checking on startup if the database is up-to-date via a JDBC connection. If the DB is not up-to-date, it performs an update routine by executing SQL scripts.

I can’t control when instances get startet. Therefore, I need to ensure that only a single instance is performing a database update at the same time. Ideally, I would need to lock the complete database, but according to

http://www.postgresql.org/docs/8.4/static/explicit-locking.html

and

http://wiki.postgresql.org/wiki/Lock_database

PostgreSQL doesn’t support it (I’m still using version 8.4).

What other options do I have?

  • 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-10T20:15:56+00:00Added an answer on June 10, 2026 at 8:15 pm

    If you control the code for all the instances, then you can create a table in the database where each instance that starts, looks in this table for a record with a timestamp. Lets call it your “lock” record.

    If a process finds that the lock record does not exist, then it inserts the record and processes the data you require.

    If a process finds that the lock record does exist then you can assume that another process has created it and do nothing, busy wait, or what ever.

    With this design you are effectively creating a “lock” in the database to synchronize your processes with. You code it, so all processes know they have to adhere to the logic of the lock record.

    Once the first process that has the lock, has completed processing, it should clear the lock record so the next restart behaves correctly. You also need to think about the situation where the lock has not been cleared due to a server error, or execution erorr. Typically, if the lock is older than n minutes you can consider it to be “stale”, therefore delete it, and create it again (or just update it).

    When dealing with the “lock” record be sure to utilise the Serializable isolation level on your DB connection in order to guarantee atomicity.

    The Service layer of your Java code can enforce with your locking strategy prior to calling your Data Access layer. It won’t matter whether you use Hibernate or not, as it’s just application logic.

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

Sidebar

Related Questions

I have a java webapp which needs to upload files via http and then
I am trying to run a Java webapp build instance but it stops in
For my java webapp, I would like a log-in form to appear on each
I got a bunch of servlet context listeners in my Java webapp, each of
Answer: My Spring 3 Java webapp is acme. I had this for my JQuery
I'm running a java webapp with a simple mvn jetty:run , using the latest
I'm renovating a legacy Java webapp. I redid a screen that displays the results
I'm writing some acceptance tests for a java webapp that returns JSON objects. I
I have a Java EE webapp that works perfectly when I run it on
I've been converting a Java Servlet based webapp as a means of learning Spring.

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.