[JIRA] Created: (LBSITE-36) Example 7.5 Is Not Thread-Safe

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: Logback dev list 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

[ http://jira.qos.ch/browse/LBSITE-36?page=com.atlassian.jira.plugin.system.is... ] john jimenez commented on LBSITE-36: ------------------------------------ I made it a major because the back drop of the example is highlighting the inherent thread-safetiness of MDC.
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: Logback dev list
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

[ http://jira.qos.ch/browse/LBSITE-36?page=com.atlassian.jira.plugin.system.is... ] john jimenez commented on LBSITE-36: ------------------------------------ Instead of synchronizing the points of userRegistered access, one can store it in the session or in this particular implementation the request.
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

[ http://jira.qos.ch/browse/LBSITE-36?page=com.atlassian.jira.plugin.system.is... ] 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

[ http://jira.qos.ch/browse/LBSITE-36?page=com.atlassian.jira.plugin.system.is... ] Ceki Gulcu resolved LBSITE-36. ------------------------------ Fix Version/s: 0.9.19 Resolution: Fixed Fixed along the lines suggested by Ralph. (Thanks Ralph).
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 Fix For: 0.9.19
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

[ http://jira.qos.ch/browse/LBSITE-36?page=com.atlassian.jira.plugin.system.is... ] Ceki Gulcu edited comment on LBSITE-36 at 3/18/10 7:13 PM: ----------------------------------------------------------- John, thank you for reporting this issue. It was fixed along the lines suggested by Ralph. (Thanks Ralph). was (Author: noreply.ceki@qos.ch): Fixed along the lines suggested by Ralph. (Thanks Ralph).
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 Fix For: 0.9.19
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
participants (3)
-
Ceki Gulcu (JIRA)
-
john jimenez (JIRA)
-
Ralph Goers (JIRA)