日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jmc线程转储_使线程转储智能化

發布時間:2023/12/3 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jmc线程转储_使线程转储智能化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

jmc線程轉儲

很久以前,我了解了一個稱為Log MDC的東西,我對此非常感興趣。 我突然意識到日志文件中發生的一切,并指出了特定的日志條目,并找到了對錯,特別是在調試生產中的錯誤時。

2013年,我受委托從事一個項目,該項目正在經歷一些麻煩的水域(幾件事的結合),幾乎每個星期我都必須經歷幾個Java線程轉儲,以弄清應用程序中發生的事情以使其停止。 另外,有時候我不得不將諸如AppDynamic,jProfiler,jConsole之類的探查器全部連接到應用程序,以試圖找出問題所在,更重要的是是什么引發了問題。 jStack是我曾經使用過的最有用的工具之一,但是顛簸的線程轉儲沒有我可以使用的上下文信息。 我被困在看到10(s)個轉儲,其中包含導致類的原因的類的堆棧跟蹤,但是沒有有關什么是什么以及導致問題的輸入的信息,并且它很快就令人沮喪。 最終,我們找到了問題,但是它們主要是經過幾輪使用各種數據集進行的深度調試之后。

一旦完成該項目,我發誓我再也不會陷入那種境地了。 我探索了可以使用類似于Log4j的NDC但在線程中使用它的方式,以便我的轉儲有意義。 而且我發現我可以更改ThreadName。 我的下一個項目確實非常有效地使用了它。 我最近遇到了一篇文章,很好地解釋了這個概念。 我不會重寫他們所說的所有內容,因此這里是他們博客文章的鏈接 。

所以上周我開始一個新項目,當我開始編碼框架時(使用Spring 4.1和Spring Boot),這是我為應用程序編寫的第一個類,并確保過濾器盡快進入代碼。幫助我們進行后期制作,但也使我的開發日志有意義。

下面是Log4j NDC和設置ThreadName的代碼副本。

import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date;import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.filter.OncePerRequestFilter;/*** This is a very Spring opinionated HTTPFilter used for intercepting all requests and decorate the thread name with additional contextual* information. We have extenced the filter from {@link OncePerRequestFilter} class provided by Spring Framework to ensure that the filter is absolutely * executd only once per request. * * The following information will be added:* <ul>* <li>Old Thread name: to ensure that we are not losing any original context with thread names;</li>* <li>Time when the request was intercepted;</li>* <li>The RequestURI that proviced information on what RestFUL endpoint was accessed as part of this request;</li>* <li>A Token that was received in the header. This token is encrypted and does not exposes any confidential information. Also, this token provides* context which helps during debugging;</li>* <li>The Payload from the token. This information will be very helpful when we have to debug for issues that may be happening with a call request* as this holds all the information sent from the called.</li>* </ul>* * This filter will also reset the ThreadName back to it's original name once the processing is complete.* * @author Kapil Viren Ahuja**/ public class DecorateThreadNameFilter extends OncePerRequestFilter {@Overrideprotected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)throws ServletException, IOException {final Logger LOGGER = LoggerFactory.getLogger(DecorateThreadNameFilter.class);final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");Thread thread = Thread.currentThread();String threadOriginalName = thread.getName();String uri = request.getRequestURI();String time = dateFormat.format(new Date());String token = request.getHeader("authorization");try {thread.setName(String.format("%s StartTime \"%s\" RequestURI \"%s\" Token \"%s\"", threadOriginalName, time, uri, token));} catch (Exception ex) {LOGGER.error("Failed to set the thread name.", ex);// this is an internal filter and an error here should not impact// the request processing, hence eat the exception}try {filterChain.doFilter(request, response);} finally {try {thread.setName(threadOriginalName);} catch (Exception ex) {LOGGER.error("Failed to reset the thread name.", ex);// this is an internal filter and an error here should not// impact the request processing, hence eat the exception}}} }/*** Generic filter for intercepting all requests and perform the following generic tasks:* * <ul>* <li>Intercepts the request and then pushed the user domain into the session if one exists.</li>* <li> Pushes a uniquely generated request identifier to the LOG4J NDC context. This identifier will then be prepended* to all log messages generated using LOG4J. This allows tracing all log messages generated as part of the same* request; </li>* <li> Pushes the HTTP session identifier to the LOG4J NDC context. This identifier will then be prepended to all log* messages generated using LOG4J. This allows tracing all log messages generated as part of the same HTTP session;* </li>* <li> Pushes the IP address of the client to the LOG4J NDC context. The IP address will then be prepended to all log* messages generated using LOG4J. This allows tying back multiple user sessions initiated with the same logon name to* be correctly tied back to their actual origins. </li>* </ul>*/ public class RequestInterceptorFilter implements Filter {/*** <p>* <ul>* <li>Initializes the LOG4J NDC context before executing an HTTP requests.</li>* <li>Pushes the domain into the session</li>* </ul>* </p>*/public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{HttpServletRequest httpRequest = (HttpServletRequest) request;if (httpRequest.isRequestedSessionIdFromCookie() && !httpRequest.isRequestedSessionIdValid()){// TODO: Need to define an session expiration page and redirect the application to that page// As of now this is a non-issue as we are handling session expirations on Flex (Front-end) and hence// no request will come to server in case the session timeout occurs// HttpServletResponse httpServletResponse = (HttpServletResponse) response;// httpServletResponse.sendRedirect(httpRequest.getContextPath() + "?expired");}else{// Create an NDC context string that will be prepended to all log messages written to files.org.apache.log4j.NDC.push(getContextualInformation(httpRequest));// Process the chain of filterschain.doFilter(request, response);// Clear the NDC context string so that if the thread is reused for another request, a new context string is// used.org.apache.log4j.NDC.remove();}}public void init(FilterConfig arg0) throws ServletException{}public void destroy(){}/*** <p>* Generates the Contextual information to be put in the log4j's context. This information helps in tracing requests* </p>* * @param httpRequest* @return*/private String getContextualInformation(HttpServletRequest httpRequest){String httpRequestIdentifier = UUID.randomUUID().toString();String httpSessionIdentifier = httpRequest.getSession().getId();String clientAddress = httpRequest.getRemoteAddr();StringBuffer logNDC = new StringBuffer(httpRequestIdentifier + " | " + httpSessionIdentifier + " | " + clientAddress);String userName = (String)httpRequest.getSession().getAttribute(WebConstants.USERNAME);if (userName != null){logNDC.append(" | " + userName);}String domain = (String)httpRequest.getSession().getAttribute(WebConstants.DOMAIN);if (domain != null){logNDC.append(" | " + domain);}// Create an NDC context string that will be prepended to all log messages written to files.return logNDC.toString();} }

翻譯自: https://www.javacodegeeks.com/2015/08/making-thread-dumps-intelligent.html

jmc線程轉儲

總結

以上是生活随笔為你收集整理的jmc线程转储_使线程转储智能化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 人人免费操| 麻豆传媒网址 | 性生活视屏 | 成人在线高清视频 | 国产精品66| 欧美性做爰猛烈叫床潮 | 最新欧美大片 | 欧美日色| 少妇激情偷人三级 | 高h视频在线播放 | 天天想你在线观看完整版电影高清 | 国产精品福利一区二区三区 | 91免费看大片 | 咪咪色图 | 亚洲精品在| 免费观看成人 | 手机成人在线视频 | 免费一区二区视频 | 免费拍拍拍网站 | 国产精品一区二区在线看 | 少妇被粗大猛进进出出s小说 | 农村妇女毛片精品久久久 | 91美女在线视频 | 我要操婊| 一级做a视频 | 天堂伊人网| 在线观看成人 | 啦啦啦免费高清视频在线观看 | 欧美视频免费看 | 青青草原在线免费 | 日本人dh亚洲人ⅹxx | 国产精品少妇 | 国产欧美精品 | 99久久精品免费看国产四区 | 青青五月天 | 欧美人xxxx| 欧美国产成人精品一区二区三区 | 国产盗摄精品一区二区酒店 | 福利片一区二区 | 久久国产露脸精品国产 | 欧美v日韩 | 午夜免费成人 | 国产精品免费av一区二区三区 | av毛片在线 | 五月天婷婷导航 | 99久久婷婷国产一区二区三区 | 国产成年无码久久久久毛片 | 夜夜精品一区二区无码 | 午夜av剧场| 国产香蕉视频在线 | 草草影院欧美 | 亚洲精品乱码久久久久久国产主播 | 国产一线二线在线观看 | 亚洲中文字幕无码不卡电影 | 狠狠干91| 免费美女毛片 | 国产欧美一区二区三区在线老狼 | 久草免费在线 | 国产在线999| 国产在线免费观看 | 天堂资源| 一级黄色在线播放 | 亚洲毛片一区 | 国产又粗又猛又爽69xx | 亚洲视频在线观看免费 | www.尤物 | 一区二区三区视频免费在线观看 | 亚洲孕交 | 伊人狠狠干 | 久久精彩 | 黄色片在线免费 | 亚洲乱码在线 | 一品毛片 | 午夜精品福利在线 | 天天碰天天干 | 成人自拍偷拍 | 色偷偷噜噜噜亚洲男人 | 亚洲色图欧美另类 | 国产欧美日韩综合精品 | 国产电影一区二区三区 | 日韩av在线看免费观看 | 色乱码一区二区三在线看 | 公侵犯人妻一区二区 | 日日操夜夜草 | 欧洲亚洲一区二区三区 | 日韩久久免费视频 | 好男人在线视频 | 男女69视频 | 男男免费视频 | 先锋资源久久 | 国产一区二三区 | 男女插插插网站 | 综合影院 | 国产区av | 欧美中文字幕视频 | 国产高潮流白浆喷水视频 | 久久av一区二区三区漫画 | 超碰在线公开 | 麻豆免费在线 |