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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:50:05+00:00 2026-05-14T18:50:05+00:00

Disclaimer : I already asked this question , but without the deployment requirement. I

  • 0

Disclaimer: I already asked this question, but without the
deployment requirement. I got an
answer that got 3 upvotes, and when I
edited the question to include the deployment requirement the answer then
became irrelevant. The reason I’m
resubmitting is because SO considers
the original question ‘answered’, even
though I got no meaningful upvoted
answer. I opened a uservoice
submission
about this problem.
The reason I reposted is so StackOverflow consider the original question answered, so it doesn’t show up on the ‘unanswered questions’ tab.

Which distributed lock service would you use?

Requirements are:

  1. A mutual exclusion (lock) that can be seen from different processes/machines
  2. lock…release semantics
  3. Automatic lock release after a certain timeout – if lock holder dies, it will automatically be freed after X seconds
  4. Java implementation
  5. Easy deployment – must not require complicated deployment beyond either Netapp, MySql or GigaSpaces. Must play well with those products (especially GigaSpaces – this is why TerraCotta was ruled out).
  6. Nice to have: .Net implementation
  7. If it’s free: Deadlock detection / mitigation

I’m not interested in answers like “it can be done over a database”, or “it can be done over JavaSpaces” – I know. Relevant answers should only contain a ready, out-of-the-box, proven implementation.

  • 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-14T18:50:06+00:00Added an answer on May 14, 2026 at 6:50 pm

    Here’s the outline of a GigaSpaces based answer that meets your criteria, depending on exactly what you mean in criteria 3. I work with GigaSpaces from .Net, not Java:

    Create a locking class with a SpaceID+SpaceRouting property IDing what is locked and a DataMember bool property Unlocked:

    sealed public class IdLockTrans
    {
        [SpaceID]
        [SpaceRouting]
        public string ID
        {
            get;
            set;
        }
    
        [DataMember]
        public bool Unlocked
        {
            get;
            set;
        }
    
        public IdLockTrans(Id id)
        {
            ID = id.ID;
        }
    
        public IdLockTrans()
        {
        }
    }
    

    You will use GigaSpaces’ lease time for lock release after a certain
    timeout. This will cause GigaSpaces to remove IdLockTrans objects
    from the space automatically after they have been idle for the timeout
    period. The lack of an IdLockTrans for an ID means the ID is unlocked.

    Your locker class will define and initialize these class members

        private readonly ISpaceProxy _proxy;
        private readonly long _leaseTime;
    
        public override bool Lock(Id id, long timeout)
        {
            bool locked;
            IdLockTrans lockTransTemplate = new IdLockTrans(id);
            // Assume that this is a new id.
            try
            {
                _proxy.Write(lockTransTemplate, null, _leaseTime, 0, UpdateModifiers.WriteOnly);
                locked = true;
            }
            catch (EntryAlreadyInSpaceException)
            {
                using (ITransaction tx = _proxy.CreateLocalTransaction())
                {
                    try
                    {
                        lockTransTemplate.Unlocked = true;
                        IdLockTrans lockTrans = _proxy.Take(lockTransTemplate, tx, timeout);
                        locked = (lockTrans != null);
                        if (lockTrans != null)
                        {
                            lockTrans.Unlocked = false;
                            _proxy.Write(lockTrans, tx, _leaseTime, 0, UpdateModifiers.WriteOnly);
                        }
                        tx.Commit();
                    }
                    catch
                    {
                        tx.Abort();
                        throw;
                    }
                }
            }
            return locked;
        }
    
        public override void Unlock(Id lockedId)
        {
            IdLockTrans lockTrans = new IdLockTrans(lockedId);
            lockTrans.Unlocked = true;
            try
            {
                _proxy.Update(lockTrans, null, _leaseTime, 0, UpdateModifiers.UpdateOnly);
            }
            catch (EntryNotInSpaceException)
            {
                throw new Exception("IdLockTrans for " + lockTrans.ID
                    + " not found on Unlock. Lock time exceeded lease time.");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: This is for a homework assignment, but the question is not regarding the
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer This question is a repost. I originally asked it here . While there
Full disclaimer: I'm a CS student, and this question is related to a recently
The Disclaimer First of all, I know this question (or close variations) have been
Question: How can I document Ruby code using Doxygen? Disclaimer: I know ruby already
Disclaimer: the following is a sin against XML. That's why I'm trying to change
Disclaimer Yes, I am fully aware that what I am asking about is totally
Disclaimer: I have already seen the following questions and their solutions did not apply

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.