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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:10:16+00:00 2026-05-19T16:10:16+00:00

I am building a stock system which will be used over an office LAN

  • 0

I am building a stock system which will be used over an office LAN with multiple users. I have a query about using the synchronized keyword to update the stock correctly. What I wish to do is allow multiple users to update the stock but of course only allow one user to update at one time. I have created a method as follows for the update of stock:

public static synchronized boolean UpdateXYZStock(Stock so){
 //update code
}

Is this the correct way to do this?

Thanks

S.

  • 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-19T16:10:17+00:00Added an answer on May 19, 2026 at 4:10 pm

    I would lock on an instance of the object, not the class. i.e. don’t lock a static method since you’re locking the class. Further to that you may want to lock on an underlying object e.g.

    private final Object writeLock = new Object();
    
    public boolean UpdateXYZStock(Stock so) {
       synchronized(writeLock) {
          ...
       }
    }
    

    so you can control the granularity of the locking more finely (I’m assuming this method is on a component within a server and thus serving multiple clients)

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

Sidebar

Related Questions

I am building a system, mostly for consolidating learning but will be used in
I'm building out a stock management system at the moment, using Entity Framework 4.
I have assignment on my hand of building an Attendance system which I am
I am using the stock SDK for php/javascript. Now the app I am building
Building an inventory system. I have lots of products and each product has three
I have a Android project which I'm building in Ant and I'm stuck on
I am building a site using fluent NHibernate, which works just fine on the
I am building a Data Access Layer which is going to be used in
I'm currently in the process of building an embedded system, using an ARM Cortex
I have an existing web application which I have been building with an ant

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.