ThreadLocal in Java

Java

Video is ready, Click Here to View ×


Use ThreadLocal for thread-safety, memory efficiency and for per-thread context storage.

Channel
———————————-
Master difficult programming concepts in few minutes. I try to explain difficult concepts like Java concurrency in simple to understand manner. Explore videos on topics like Spring Boot, Cloud Foundry, Java 8 and more. I am happy to clarify your doubts. Ask me anything in the comments. Also happy to take requests for new videos.

New video added every…

9 thoughts on “ThreadLocal in Java

  1. Great video as always, however I have a question regarding the service example. If we have a shared object that's used by multiple services, then were does it live? In other words, I'm having a hard time wrapping my head around this example. I feel like if the user context holder is supposed to be shared across multiple services, then it would have to be implemented as a distributed object running externally to the services (e.g. memcached).

    Said another way, since the user context holder would be local to the request thread then how would an external service have visibility into the threadlocals running inside a different JVM? For example, service1 gets a request and gets a thread local user context object that it populates before calling service 2. When service 2 is called by service1, service2 gets its own request thread (because it's a different service running on a different jvm). Thoughts?

  2. Thanks for the video. Liked first, watching next. :). Definitely one of best video of Yours. Keep going.

    Clarification:
    2:25, If i have util class to do that formatting with static method, will effect be same ?

Leave a Reply

Your email address will not be published. Required fields are marked *