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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:38+00:00 2026-05-26T21:38:38+00:00

I am having a multi-thread application using a single static class which provides a

  • 0

I am having a multi-thread application using a single static class which provides a list. I want getters of the static class to work freely (not synchronized against each other) but when a setter is working I want all getters to get locked and wait until setter’s job is done. I don’t want to lock getters when they are called together since it would degrade performance a lot. Getters are called 1,000,000 times per day and setter is only supposed to work once per day.

  • 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-26T21:38:39+00:00Added an answer on May 26, 2026 at 9:38 pm

    Consider using a java.util.concurrent.locks.ReadWriteLock implementation, such as ReentrantReadWriteLock (see javadoc)

    A ReadWriteLock maintains a pair of associated locks, one for read-only operations and one for writing. The read lock may be held simultaneously by multiple reader threads, so long as there are no writers. The write lock is exclusive.

    You would use this instead of synchronized. Your getters would obtain the read lock, then release when they return, e.g.

    public String getX() {
        Lock readLock = readWriteLock.readLock();
        readLock.lock();
        try {
            return value;
        } finally {
            readLock.unlock();
        }
    }
    

    Similarly for setters methods, but using readWriteLock.writeLock() instead.

    The class would have a single ReentrantReadWriteLock object, shared by all getters and setters on each object (or, if you wish, one per getter/setter pair).

    It’s quite cumbersome, but should give good concurrency. For those reasons, you should only take this on if you really need it, and that means measuring the degraded concurrency you get if you just use vanilla synchronization.

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

Sidebar

Related Questions

I'm having trouble debugging a multi-process application (specifically using a process pool in python's
I've got a multi-user application having some critical data of the users. I am
I'm having a problem with curl_multi_* , I want to create a class /
I am having an application which has a UI module and other supporting services.
I am writing a multi-threaded .Net application in which many callers need to concurrently
I am having a multi-threaded application that fetches different web pages. For this, I've
i'm working with a multi-threaded program (using pthreads) that currently create a background thread
Having what appears to be a dead-lock situation with a multi-threaded logging application. Little
I'm trying to run a multi-threaded console app in VB and am having thread
I am writing an application which works on 3 tiers Each having multiple instances

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.