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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:11:17+00:00 2026-05-30T21:11:17+00:00

I want to submit tasks to a ForkJoinPool or ParallelArray from a thread holding

  • 0

I want to submit tasks to a ForkJoinPool or ParallelArray from a thread holding a write lock. Access to our domain model is protected by checks that the current thread holds the relevant lock. To allow FJ workers to perform tasks on it (read only, e.g. querying), they need to delegate access checks to the thread that spawned them.

I subclassed the ForkJoinWorkerThread with a reference to the spawning thread. I then subclassed ReentrantReadWriteLock and overrode isWriteLockedByCurrentThread to perform the usual check, and fall back to a check that, if the thread is an instance of the delegating FJWorker, that the delegate thread (parent) is the owner of the lock, using ReentrantReadWriteLock#getOwner():

public class DelegateAwareReentrantReadWriteLock extends ReentrantReadWriteLock {
    @Override
    public boolean isWriteLockedByCurrentThread() {
        return super.isWriteLockedByCurrentThread() || isWriteLockedByDelegateThread();
    }

    private boolean isWriteLockedByDelegateThread() {
        final Thread currentThread = Thread.currentThread();
        if (currentThread instanceof FJAccessDelegatingWorker) {
            final Thread delegate = ((FJAccessDelegatingWorker) currentThread).getDelegate();
            return delegate.equals(getOwner());
        }
        return false;
    }
}

However, the documentation for getOwner() states the following:

When this method is called by a
thread that is not the owner, the return value reflects a
best-effort approximation of current lock status. For example,
the owner may be momentarily null even if there are
threads trying to acquire the lock but have not yet done so.

I would like to understand this to mean that if I’ve submitted the tasks within a thread that has already been granted access, this method will correctly return the reference to it. Unfortunately, this is not even implied.

If I can’t use this method, what other alternatives exist for this kind of delegation?

Thank you.

  • 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-30T21:11:18+00:00Added an answer on May 30, 2026 at 9:11 pm

    I imagine that the implementation details of getOwner() are such that if there is a happens-before relationship between the thread that acquired the write lock and the thread querying the owner, that it will have determinstic behaviour that ensures the correct owner is returned. I have not checked the implementation, but it feels like this is what the comments are alluding to, and are covering the base that the behaviour can be non-deterministic while the lock is being acquired.

    However, it may be easier all around if it is possible for you to downgrade your write lock and avoid all of the delegation checking to begin with (since then each thread could own its own read lock). Perhaps it is also possible to use two separate locks, say an outer and inner lock, where the inner lock is not held for writing in this case?

    Edit:
    The implementation of getOwner() calls getState() which does a read of the volatile state variable, and this should be enough to guarantee that getOwner() will always return your parent thread if it holds the write lock.

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

Sidebar

Related Questions

I submit some some Future tasks using a CompletionService wrapped round a 2 thread
I want to load external content (from another domain) and simulate navigation, doing things
I want to submit a with using jquery as below; $(#formid).submit(); Its working perfect
I want to submit an app to the app store. The app has been
I want the submit button to disappear after it's clicked and a new layer
I want to submit a form like this: <input type=button onclick=$('#form1').submit(); value=Create /> but
I don't want to submit projectname.project folder. Now, I use like that git add
I have a case where i want to submit a form and get the
I have a form which I want to submit upon button click which is
i have a form and want to submit it with a script. i'm going

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.