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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:15:22+00:00 2026-05-20T10:15:22+00:00

How would I go about doing this in a client-server application? I want to

  • 0

How would I go about doing this in a client-server application?

I want to basically let clients access the same data through separate threads, and I want avoid concurrency thread issues so I’m asking for examples.

  • 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-20T10:15:23+00:00Added an answer on May 20, 2026 at 10:15 am

    To access the same piece of data, you just need to ensure you’re accessing the same instance of the class. So 2 threads hitting the same singleton, or the same object obtained from some factory will both be getting the same piece of data. Obviously the exact scenario depends on your application.

    Concurrency issues will generally only arise when some piece of data is being modified. Say for example you had the following class:

    class Container {
      private List<?> data;
    
      public List<?> getData() {
        return this.data;
      }
    
      public void addData(Object data) {
        this.data.add(data);
      }
    }
    

    Then that would not necessarily be thread safe. To make it thread safe, you need to lock on an object monitor. This could be done in one of two ways in this scenario:

    class Container {
      private List<?> data;
    
      public synchronized List<?> getData() {
        return this.data;
      }
    
      public synchronized void addData(Object data) {
        this.data.add(data);
      }
    }
    

    This solution would lock calls to getData and setData on the Container instance’s lock. This is fine, except if you were to add a third method to this class, which didn’t use data at all, then it would also be blocked if any thread was inside getData or setData. To make it more specific, you could do:

    class Container {
      private List<?> data;
    
      public List<?> getData() {
        synchronized (this.data) {
          return this.data;
        }
      }
    
      public void addData(Object data) {
        synchronized (this.data) {
          this.data.add(data);
        }
      }
    }
    

    This then uses the data variables object lock. The advantage of this is if you add a third method which doesn’t use data, then it won’t be blocked by calls to getData or setData.

    That’s a basic overview of Java’s concurrency safety, hope it helps.

    Note that the client-server nature of your problem doesn’t really change much. If your threads are being created by, for example, thread per request via java servlets or something then this all applies in exactly the same way.

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

Sidebar

Related Questions

How would I go about doing this: for( var i = 0; i <
Just a quick question about how you would go about implementing this. I want
How would I go about doing a query that returns results of all rows
How would you go about doing a bit shift in NASM on a register?
Since PHP has no custom-class type-casting, how would I go about doing the PHP
I'm wondering how i would go about making the following application: a user signs
Specification C# Distributed Application. Client/Server design. Client (Winforms), Server (Windows Service), Communication via .Net
What would be the best way to store data in a windows forms application?
I'm writing a client/server application that requires the server needs to be able to
I discovered twisted half-way through developing a network application. I had a working Client

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.