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

  • Home
  • SEARCH
  • 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 8790279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:36:37+00:00 2026-06-13T22:36:37+00:00

I am implementing a vaadin application following this thread local pattern . The state

  • 0

I am implementing a vaadin application following this thread local pattern.

The state of the application is modified by several worker threads. Hence, to notify the application that its state changed, I add a progress indicator.

Reading the progress indicator sample, I see this :

        // All modifications to Vaadin components should be synchronized
        // over application instance. For normal requests this is done
        // by the servlet. Here we are changing the application state
        // via a separate thread.
        synchronized (getApplication()) {
            prosessed();
        }

So basically, I think I just have to modify the call to getApplication to get the instance of my application (just call getCurrent):

  private static ThreadLocal<MyApplication> currentApplication = new ThreadLocal<MyApplication>();

    @Override
    public void init() {
        setCurrent(this); // So that we immediately have access to the current application

        // initialize mainWindow and other stuff

        // Register a transaction listener that updates our ThreadLocal with each request
        if (getContext() != null) {
            getContext().addTransactionListener(this);
        }   
    }

    /**
     * @return the current application instance
     */
    public static MyApplication getCurrent() {
        return currentApplication.get();
    }

The problem is that my worker thread dies of starvation because It cannot acquire the mutex on the application.
One solution provided by the vaadin forum is to use InheritableThreadLocal. It works but I don’t get it why.

From the javadoc :

This class extends ThreadLocal to provide inheritance of values from
parent thread to child thread: when a child thread is created, the
child receives initial values for all inheritable thread-local
variables for which the parent has values. Normally the child’s values
will be identical to the parent’s; however, the child’s value can be
made an arbitrary function of the parent’s by overriding the
childValue method in this class.

Inheritable thread-local variables are used in preference to ordinary
thread-local variables when the per-thread-attribute being maintained
in the variable (e.g., User ID, Transaction ID) must be automatically
transmitted to any child threads that are created.

My worker thread cannot get the lock because it does not receive initial values ?
Am I misinterpreting something ?
Except this problem, what are the potential pitfalls of using InheritableThreadLocal I should be aware of ?

Thanks.

  • 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-06-13T22:36:39+00:00Added an answer on June 13, 2026 at 10:36 pm

    The key for understanding how it works is method in ThreadLocal class:

    static ThreadLocalMap createInheritedMap(ThreadLocalMap parentMap) {
       return new ThreadLocalMap(parentMap);
    }
    

    It is designed to be called only from Thread constructor. The method

    protected Object childValue(Object parentValue)
    

    of InheritableThreadLocal class is used to set the initial value of the InheritableThreadLocal variable in the child thread as a function of a ThreadLocal variable (passed as a parameter) in the parent thread. This method is called from within the parent thread before the child thread is created and the default implementation will make the child values identical to parent’s, but we can override the childValue() method to set the child value as a function of the parent value for those ThreadLocals which have values in the parent thread. By default the childValue() returns the same input argument, but again an override of the childValue() method might change this behavior as well.

    So InheritableThreadLocal works almost like ThreadLocal and it has the same synchronization pitfalls.

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

Sidebar

Related Questions

Hi I am implementing an application in Vaadin where I have a HorizontalSplitPanel with
After implementing the data structure suggested in this thread , I decided to fill
implementing publishActivity in PHP using the REST API using this code: $activity = array(
When implementing the Strategy Pattern, where does one put the code that determines which
Has anyone tried implementing a web application with Clojure ( using Compojure ) and
Implementing Document-View pattern I faced the problem: standard generic collections and dictionaries ( List<T>
When implementing move constructors and move assignment operators, one often writes code like this:
Whilst implementing my first MVVM application in WPF, I've been wondering about the pros
In implementing M-V-VM in a project and following advice of Karl Shifflett about implementing
Im implementing NFS and almoste done but the RFC section 3.3.8 says this in

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.