echo无法清空日志

一、问题描述

前段时间webmethod应用所在物理机磁盘满了,于是清理其日志。但是有个通过Log4j2记录的日志文件在执行cat /dev/null | tee *.log后大小又瞬间恢复到原来尺寸。当时感觉应该应该是使用Appender导致的,但时苦于没有找到log4j2.xml配置也就搁置了。

二、问题探究

阅读更多

Java异常堆栈丢失仅剩一行

一、问题描述

今日在测试环境帮研发定位问题时,查看日志,发现异常信息丢失,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2021-12-16 14:05:27[ http-nio-8082-exec-10:519172801 ] - [WARN ] com.xxx.xxx.XxxFilter-doFilter:107 - 解析Tenant出错, 错误信息:Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
Caused by: java.lang.NullPointerException
阅读更多

ServiceLoader

一、Java SPI使用

1
2
3
4
5
6
ServiceLoader<MySpiInterface> load = ServiceLoader.load(MySpiInterface.class);
Iterator<MySpiInterface> iterator = load.iterator();
while (iterator.hasNext()) {
MySpiInterface obj = iterator.next();
obj.doSomethind();
}
阅读更多

使用hsdb查看运行时类

1)可选,为方便起见先创建一个JAVA_HOME的软连接

ln -s /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home jdk8

2)启动hsdb

阅读更多

断言

一、业务代码中禁用Assert

  • assert在非测试执行时是默认关闭的,需要加-ea参数才能开启;
  • 避免非测试用例中写assert,不然会被自己蠢哭;
阅读更多

误用BlockingQueue方法导致日志丢失

一、背景

最近研发反映线上EDI的日志有丢失现象,经过审查代码发现,本机使用的BlockingQueue方法有误,使用的BlockingQueue#add方法,此时当队列满时会插入失败,返回false。
EDI运行时持久化逻辑

阅读更多

System.currentTimeMillis()与GMT

一、System.currentTimeMillis()函数注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public final class System {
/**
* Returns the current time in milliseconds. Note that
* while the unit of time of the return value is a millisecond,
* the granularity of the value depends on the underlying
* operating system and may be larger. For example, many
* operating systems measure time in units of tens of
* milliseconds.
*
* <p> See the description of the class <code>Date</code> for
* a discussion of slight discrepancies that may arise between
* "computer time" and coordinated universal time (UTC).
*
* @return the difference, measured in milliseconds, between
* the current time and midnight, January 1, 1970 UTC.
* @see java.util.Date
*/
public static native long currentTimeMillis();
}
阅读更多

文件正确写入bom

0. 什么是BOM(byte order mark, 字节序标记)?

bom可认为是unicode编码格式的一个标识。bom的字符为\uFEFF,不同编码格式下会encoding为不同的字节序,如下图:
bom encoding table

阅读更多

工厂类中使用ThreadLocal的陷阱

1. 背景

由于EDI已有的日志结构比较混乱,多个人都写了自己的LoggerHelper工具类。近期的工作主要是写一个新的日志框架,通过SPI方式加载Appender的实现,并替换掉之前的日志内容。

阅读更多

包冲突

Jar包冲突的说法其实比较笼统,具体而言是类冲突。两个JAR包内包含了某个完全限定名相同的类。

一、Jar包冲突的场景

阅读更多