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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:57:12+00:00 2026-06-10T15:57:12+00:00

A simple example: class Account{ private String account_name; private String password; private double balance;

  • 0

A simple example:

      class Account{
           private String account_name;
           private String password;
           private double balance;

           public synchronized double getBalance(){
                  return balance;
           }
           public synchronized void setBalance(double add){
                  balance += add;
           }
      }

From my understanding that acquiring the lock associated with an object does not prevent other threads from accessing that object. They have to be the same lock to prevent accessing.

So if two person tried accessing the same account at different ATM, then it will create two different instances of this Account object, correct ? so then it’s not guarded with the same lock, right ?

lets say if Person A (Thread A) tried to save money into the account while at the same time Person B(Thread B) tried getting to total balance of the account.

How does it work ? Do they cache the Account while be using so it will return the same Account object when the next request comes in ?

  • 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-10T15:57:14+00:00Added an answer on June 10, 2026 at 3:57 pm

    Synchronized methods will lock the object instance. However, if there is a method, which is not synchronized concurrent access can happen.

    ATM machines don’t access your account – the bank server does. The ATM machine is just a client. So accessing the same account from 2 different ATMs would be guarded by the bank server, which has only one instance of this account in it’s memory / database (probably protected by some locking mechanism and not written in Java).

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

Sidebar

Related Questions

Consider this simple example - public class Person { private String name; private Date
Best explained with code I think, this is just a simple example: public class
here is a simple example to clear my intentions. class A { public int
First, a simple example to describe my problem. Model public class User { public
What is bad on this code? It is simple example: class Program { public
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
Here is a simple example: class Class_A { protected $_property; public function method() {
I have a very simple class public class SimpleClass // abreviated for this example
Please look at the simple example: class A: def __init__(self, flag): self.flag = flag
I can't get past this issue I am having. Here's a simple example: class

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.