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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:21:10+00:00 2026-05-26T22:21:10+00:00

Say my web server receives two simultaneous requests. It will handle each request in

  • 0

Say my web server receives two simultaneous requests.

It will handle each request in a separate thread.

It will create a JPA entity manager for each thread.

Now let’s say each thread requests the same database row. Say I have a table called Cars. I have a car with id = 5. I do a find for a car with id = 5 in both threads.

So I now have two separate objects representing the same entity.

Now let’s say I update the gasLevel of the car in thread 1. If I get the gasLevel in thread 2, will I get the new gasLevel set by thread 1?

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

    No, you won’t, because as you said, you have two different instances of the entity. If they both update the gasLevel to a different value, then the last commit will win.

    That’s one of the reasons to implement optimistic locking, using a version field annotated with @Version: the last commit will fail because some other transaction has updated the value between the moment the entity was loaded and the moment its new state is flushed.

    Note that even if thread 1 reads the value (7), changes it to 8, flushes, and thread2 then reads the value, thread 2 will still see 7 in the default case, because the default case is to use the READ_COMMITTED isolation level. This means that one transaction only sees the data that has been committed by other transactions. This depends on the database, though. HSQLDB for example only supports READ_UNCOMMITTED.

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

Sidebar

Related Questions

Lets say I have several web sites on my web server, all as applications
So, lets say I'm writing a web server and I want to support very
My web server has a peculiar behavior: Let's say my website URL is http://my-domain.com
We've got a web server which has been running a number of separate applications
If we are to separate our web server and app server, would we need
Say I want to run a simple Python script that is a web server.
Say I have a web service where I want to serve the content only
Say a web page has a string such as I am a simple string
Why do we say that web services are stateless?
Say in my web.xml file, I define a servlet like so: <url-pattern>/MyURL/*</url-pattern> How do

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.