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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:29:16+00:00 2026-05-20T22:29:16+00:00

I want to have a second lock around a map which is of type

  • 0

I want to have a second lock around a map which is of type Collections.synchronizedMap. How can I have it?

  • 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-20T22:29:17+00:00Added an answer on May 20, 2026 at 10:29 pm
    private ReadWriteLock mapLock = new ReentrantReadWriteLock();
    mapLock.writeLock().lock(); 
    try {  
       final TableManagementInfo table = TABLES.get(mKey);
    

    Am i doing wrong..??

    Depends what you are trying to do and what code follows.

    You should probably finally unlock(). But then one has to ask why you do not want to use a synchronized block instead (see the answer by @WhiteFang34).

    Also, if all you are doing in the critical section is calling a single get on an already concurrent map, you don’t need the extra lock.

    If on the other hand, you do other things, you probably don’t need to use a synchronized map (with its insufficient locking) in the first place (just use your outer lock if you can do so in all places where the map is used).

    To sum up, you do not want to use ReadWriteLock when a synchronized block will do, and you do not want to use two locks where one will do (use either SynchronizedMap or the application-level lock, but not both).

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

Sidebar

Related Questions

we want to have the second biggest element. We first use ANY to exclude
I want to have a clock showing current time and refreshes every second. The
I have a JSON file and want to parse value of variable second value
I have a texbox and I want to change it's content every second in
I have two table first is TABLE_SUBJECT and second is TABLE_CHAPTER.Now i want to
I have different select boxes. I want to select second one with related id.
I have a problem about div position relative alignment. I want the second div
I have two QTreeWidgetItem that are top level. I want to make the second
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
am having game with 10 levels. i want to change the second level lock

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.