我使用this链接执行了一个简单的线程程序,但是
日志文件未创建。有人可以帮我解决这个问题吗?
我的代码:
//////////////////////////////主类/////////////// ////////////////
package PkgThread;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args){
ExecutorService executor = Executors.newFixedThreadPool(5);
int count = 1;
while(count<=5){
Head head = new Head();
head.setName("head-" + count);
executor.execute(head);
count++;
}
executor.shutdown();
}
}
14:59:12,682 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 无法找到资源[logback.groovy] 14:59:12,683 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 无法找到资源[logback-test.xml] 14:59:12,683 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 找到资源[logback.xml] at
[file:/D:/PrcSHERM/ProjThread/target/classes/logback.xml]
14:59:12,732 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
14:59:12,745 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.sift.SiftingAppender]
14:59:12,748 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE-THREAD]
14:59:12,770 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.sift.MDCBasedDiscriminator] for [discriminator] property
14:59:12,778 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
14:59:12,780 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
14:59:12,808 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
14:59:12,808 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
14:59:12,808 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
14:59:12,808 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.mkyong.analyzer.core] to DEBUG
14:59:12,808 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.mkyong.analyzer.core] to false
14:59:12,808 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE-THREAD] to Logger[com.mkyong.analyzer.core]
14:59:12,809 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[com.mkyong.analyzer.core]
14:59:12,809 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
14:59:12,809 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
14:59:12,809 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
14:59:12,810 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@fda5bfa - Registering current configuration as safe fallback point
答案 0 :(得分:1)
我找到了我出错的地方
我在logback.xml中指定了错误的包名称
包名称必须从com.mkyong.analyzer.core更改为我自己的包
名。现在,日志文件正在创建。
答案 1 :(得分:0)
您将任务提交到Executor
只是为了之后直接关闭它。您必须提供Executor
时间来实际执行它们,即使用boolean awaitTermination(long timeout, TimeUnit unit)
。
此外:我没有看到任何记录。