[logback-dev] [JIRA] Commented: (LBSITE-36) Example 7.5 Is Not Thread-Safe

Ralph Goers (JIRA) noreply-jira at qos.ch
Wed Feb 10 01:12:33 CET 2010


    [ http://jira.qos.ch/browse/LBSITE-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=11519#action_11519 ] 

Ralph Goers commented on LBSITE-36:
-----------------------------------

I concur that the way userRegistered is used is not thread safe. However, in this example there is no need to store it in the session or the request.  Instead, define registerUserName as 

private boolean registerUsername(String username) {
   
    if (username != null && username.trim().length() > 0) {
      MDC.put(userKey, username);
      return truel
    }
    return false;
  }

then in doFilter do

String userName;
if (principal != null) { 
  username = principal.getName();
} else {
  username = (String) req.getSession().getAttribute(userKey);
}
boolean userRegistered = registerUserName(userName);

> Example 7.5 Is Not Thread-Safe
> ------------------------------
>
>                 Key: LBSITE-36
>                 URL: http://jira.qos.ch/browse/LBSITE-36
>             Project: logback-site
>          Issue Type: Bug
>          Components: Documentation
>    Affects Versions: unspecified
>            Reporter: john jimenez
>            Assignee: Ceki Gulcu
>
> Example 7.5 in 
> http://logback.qos.ch/manual/mdc.html
> is not thread-safe because
> userRegistered
> is declared as a global variable.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list