Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggingContext instead of ThreadLocal InheritableThreadLocal #11

Open
tuxBurner opened this issue Feb 18, 2019 · 0 comments
Open

LoggingContext instead of ThreadLocal InheritableThreadLocal #11

tuxBurner opened this issue Feb 18, 2019 · 0 comments

Comments

@tuxBurner
Copy link
Member

Damit LoggingContext auch in Child threads verwendet wird. wird anstatt des ThreadLocals InheritableThreadLocal verwendet.

Im Child wird dann die gleiche Map verwendet.

Leider ist es nicht ganz so einfach. Innerhalb der child threads werden auch schreiboperationen an das Parent weitergeleitet. Die Map ist jedoch derzeit nicht synchronisiert.
Daher wird eine Art copy on write benötigt.

 private static ThreadLocal<LoggingContext> currentContext = new InheritableThreadLocal<LoggingContext>()
  {

    @Override
    protected LoggingContext childValue(LoggingContext parentValue)
    {
      if (parentValue == null) {
        return new LoggingContext();
      }
      return new LoggingContext(parentValue);
    }

  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant