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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:24:30+00:00 2026-06-10T19:24:30+00:00

I am using Java EE 6 with JBOSS7 and JPA2 + Hibernate. For my

  • 0

I am using Java EE 6 with JBOSS7 and JPA2 + Hibernate. For my client I provide a REST api.

My concern is how to efficiently ensure that no resources where modified concurrently. Should happen too often, but in case it happens I would like to ensure proper handling.

My approaches so far:

  1. Map<String, ReentrantLock> to store the locks. (my ids are always
    UUIDs) Locks are created on demand if missing in map. On this
    approach i like that concurrent access will be blocked and i can
    control how long the other thread tries to lock the resource.

  2. Use JPA2 optimistic locking.

Which one would you recommend? Or is there an even better approach?

  • 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-10T19:24:31+00:00Added an answer on June 10, 2026 at 7:24 pm
    1. seems error-prone, plus it might not scale. I’ve never seen such
      design and would discourage it.
    2. transactions with optimistic
      locking is a viable option. In this case, some transaction might
      fail and you will need to deal with errors and retry.
    3. transactions with pessimistic locking is another viable option. It’s
      like 1) but using the database to lock and order operations. AFAIK,
      JPA support pessimistic locking as well. Otherwise you can use
      SELECT FOR UPDATE(supported by most DBMS) to explicitely acquire row locks. Make sure you
      figure out a scheme were locks are acquired in consistent order, to
      avoid deadlocks.

    The choice between 2-3 depends on the use case, e.g. if contention is expected to be high or not, or whether it is easy to retry a failed transaction.

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

Sidebar

Related Questions

I am using jboss as the server and my java program as the client,
Imagine you are developing a Java EE app using Hibernate and JBoss. You have
Using Java (1.6) I want to split an input string that has components of
I am using Eclipse and JBoss Tools to generate Java classes from existing Hibernate
I want to implement a one-to-many relation using Hibernate (in Java). I have two
Is it possible to get hibernate statistics as generated by hibernate using java melody
I am putting together a regular Java EE application on jboss7 that will use
I am using the latest Eclipse for Java EE & the latest JBoss Tools
Using Java IO streams, it is quite often we use objects solely as constructors
Using java If I store windows paths in a h2 database, and then try

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.