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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:17:10+00:00 2026-06-13T19:17:10+00:00

What has kept me from using Akka regularly (in Java) is a concern I

  • 0

What has kept me from using Akka regularly (in Java) is a concern I have with libraries that use ThreadLocals.

That is I think some Akka Dispatchers may cause ThreadLocal variables to be left behind, or missing all together. So the obvious solution would be to avoid using ThreadLocals but there are so many libraries that use them: Spring, Wro4j, Log4j, etc etc…

ThreadLocals normally work fine in Servlet Container. That is because even though containers have threadpools the request is mainly a synchronous lifecycle, thus generally at the end of a request things like Spring and Wro4J will clean up there threadlocals. Some containers like Tomcat even monitor threadlocal leaks.

Such is not the case in Akka from what I understand.

How do people get around this issue?

For now I just avoid using Akka and use a Message Queue (like RabbitMQ or ActiveMQ) but would like to use Akka as it covers a wider range of async problem/solution.

I also think Netty has similar issues but I believe Netty offers some sort Channel Context object that you can use in place of ThreadLocal and in theory some libraries may know to use that instead of ThreadLocal.

  • 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-13T19:17:12+00:00Added an answer on June 13, 2026 at 7:17 pm

    The easiest way to solve it is to demarcate the use of ThreadLocals, so you create a method as such:

    def withSecurityContext[T](thunk: => T)(implicit secCtx: SecurityContextFetcher): T = {
      val old = threadLocalSecurityContext.get
      threadLocalSecurityContext.set(secCtx.fetch)
      try thunk finally threadLocalSecurityContext.set(old)
    }
    

    Then inside your Actor or whatnot:

    class MyActor extends Actor {
        def receive = {
          case "foo" => withSecurityContext { beAwesome() }
        }
    }
    

    In general though, I’d avoid ThreadLocals because they don’t really blend in with distributed systems. They only work in clearly demarcated sections.

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

Sidebar

Related Questions

I have a datagridview that has been populated from a datatable using the datasource
All, I have an issue with a remote ftp server that has kept me
I'm using the jQuery Validation plugin on my forms. I have some groups of
I have a GUI C# application that has a single button Start/Stop. Originally this
I have a View that is linked to my ViewModel using a DataTemplate, like
I've got an app that displays information from our web service. The user has
I'm using Valum's AJAX uploader, which is quite nice. I have a form that
I found code online that displays how to use threads from a tutorial by
Has anyone ever used the hidden class PackageParser in Android source code with java
Has anyone successfully tried minifying AND concatenating all the jqGrid locale files so that

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.