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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:37:00+00:00 2026-05-26T03:37:00+00:00

We have a use case where we need to acquire a lock and send

  • 0

We have a use case where we need to acquire a lock and send a notification if acquiring the lock takes more than 5 mins. We should still be waiting for the lock forever.

We are using re-entrant locks and lock.tryLock(5, TimeUnit.Minutes) is not enough as it comes out after 5 minutes.

The option that we tried was:

while(!lock.tryLock(5, TimeUnit.minutes)) {
    // send notification
}

But I guess, this would result in losing the fairness of the lock (order in which lock has been requested for)

Did anyone face such use cases, if yes, please explain how it was solved.

We prefer not to have hand-rolled solution of maintaining the locks and corresponding wait thread’s meta info (like when it was initiated for lock acquisition) in some context and another thread continuously polling this entire context to see if it has any wait threads waiting for more than 5 minutes.

  • 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-26T03:37:00+00:00Added an answer on May 26, 2026 at 3:37 am

    Set up a ScheduledExecutorService. Before acquiring the lock, schedule a task to fire in 5 minutes and keep the Future. When the lock is acquired, cancel the Future.

    ScheduledExceutorService ses;
    Future f = ses.schedule(new Runnable(){...}, 5, TimeUnit.Minutes);
    lock.lock();
    f.cancel();
    

    If you acquire the lock before the submitted task has executed, it should be cancelled.

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

Sidebar

Related Questions

Have a use case wherein need to maintain a connection open to a database
I have a use case where I need to call a (non-static) method in
I have a use case where if a number lies between 0-10 it should
I'm looking for a good reader/writer lock in C++. We have a use case
I am pretty new to android. I have a use case where I need
In Zend Framework, I have a common use case where I need to propagate
I have the following use case: I need to process a big number of
I have a use case where I need to add information about the user
I have a use case , where I need to display some log files
We have the use case that we need to output text that is a

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.