In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to complete the information output processing in Java multithreading debugging, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Java multithreading debugging is very tedious, but we still need to continue to learn about it. Let's take a look at the key points we need to pay attention to in Java multithreaded debugging. In order to see the intermediate results, it is common to output the information to System.out.
This creates a problem: the output information of many threads is simply output to the console, which is troublesome when we want to see the intermediate information processed by each thread itself. Recently, in a practical project, Log4j was used to output each thread to its own log file, which is convenient for debugging.
1. Configure the log4j.properties file
Lg4j.rootLogger=DEBUG,stdout
# stdout is set to be a ConsoleAppender.
Log4j.appender.stdout=org.apache.log4j.ConsoleAppender
Log4j.appender.stdout.layout=org.apache.log4j.
PatternLayout
Log4j.appender.stdout.layout.ConversionPattern=
[% t] (% FJO% L) -% m% n
Log4j.additivity.log4j.stdout=false
# com.se.crawler.Crawler Appender.
Log4j.logger.com.se.Crawler.Crawler=DEBUG,Crawler
Log4j.appender.Crawler=org.apache.log4j.FileAppender
Log4j.appender.Crawler.File=Crawler.log
Log4j.appender.Crawler.Append=false
Log4j.appender.Crawler.layout=org.apache.log4j.PatternLayout
Log4j.appender.Crawler.layout.ConversionPattern=%m%n
Log4j.additivity.com.se.crawler.Crawler=false
# com.se.crawler.LinkProcessor Appender.
Log4j.logger.com.se.crawler.LinkProcessor=DEBUG,Link
Processor
Log4j.appender.LinkProcessor=org.apache.log4j.FileAppender
Log4j.appender.LinkProcessor.File=LinkProcessor.log
Log4j.appender.LinkProcessor.Append=false
Log4j.appender.LinkProcessor.layout=org.apache.log4j.
PatternLayout
Log4j.appender.LinkProcessor.layout.ConversionPattern=%m%n
Log4j.additivity.com.se.crawler.LinkProcessor=false
Description: rootLogger is the console and Crawler,LinkProcessor is two threads, which are output to Crawler.log and LinkProcessor.log files respectively.
two。 Add log code to a thread
……
Import org.apache.log4j.Logger
……
Public class Crawler extends Thread {
……
Protected static Logger logger = Logger.
GetLogger (Crawler.class)
……
Logger.debug (msg)
……
}
In this way, two log files Crawler.log and LinkProcessor.log are automatically generated while the thread is running, and the intermediate results are output to their respective log files.
This is the answer to the question about how to complete the information output processing in Java multithreaded debugging. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.