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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:53:19+00:00 2026-05-21T01:53:19+00:00

I have server service which releases the table database if a certain criterian is

  • 0

I have server service which releases the table database if a certain criterian is satisfied. It looks like this

public static void autoUnloadDbTable(final Configuration conf) {
   final String mKey = getMapKey(conf);
   final Table table = TABLES.get(mKey);
   if (table != null) {
      dblock.getLock().lock();
      table.instance.dispose();
      TABLES.remove(mKey);.....(2)
   }
   //here release lock when done...
}

But there is another operation which can run sideways when the above function is being executed

public Table getTableLocked(final Lock lock) throws FactFinderException {
   boolean loadTable = true;
   // Get the current table instance
   Table table = TABLES.get(mapKey);
   // .....(1)
   if (table != null) {
      //do something
   }

   if (loadTable) table = loadTableLocked(table);

   // lock the table, so the instance don't gets replaced
   if (lock != null) lock.lock();   
   return table.instance;
}

At (1) i need to put something because if one thread is executing the code at (2) and the other thread is at thread (2) which already have a table object but as (2) is executing so it will delete the table object and then everything beyond (1) will not have a correct value….any suggestions please…??

  • 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-21T01:53:19+00:00Added an answer on May 21, 2026 at 1:53 am

    You probably want a read/write lock around TABLES. Acquire a read lock before you do TABLES.get(…) to use something from tables , and acquire a write lock before you do TABLES.get(…) to delete from it.

    The alternative is to have a lock per table. After a TABLES.get(…) acquire the Table specific lock, then make sure the Table is still in TABLES, then perform your action with the lock. This Table specific lock can be a read/write lock as well, then only the code wishing to delete will acquire a write lock. This gets complicated when you try to add to TABLES, you will need to be clever, and probably use a ConcurrentMap for TABLES, and use putIfAbsent.

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

Sidebar

Related Questions

I have background service which access my SQL Server database. My background service working
Our database server is a SQL 2008 server. My colleagues all have XP service
I have a server written in Java that runs as a Windows service (thanks
We have a remoting singleton server running in a separate windows service (let's call
I've got a WCF service up and running on a server. We have a
I have a report in SQL Server Reporting Services (SSRS) that I'd like to
Okay this is a real headscratcher. I have an application which calls a web
I have a .NET application running on an IIS7 server. A service provider has
I have a server side service called ConstructionManager , one of its operation is
I have a windows service which is using a method from a class library

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.