类加载时的线程块

时间:2018-10-21 07:45:51

标签: java jvm

上阻塞了很多线程
    "My-remoting-thread-12" #784 daemon prio=10 os_prio=0 tid=0x00007f9418071800 nid=0x1861 waiting for monitor entry [0x00007f91de54f000]
java.lang.Thread.State: BLOCKED (on object monitor)
    at ch.qos.logback.core.util.CachingDateFormatter.format(CachingDateFormatter.java:45)
    - waiting to lock <0x000000074bc00778> (a ch.qos.logback.core.util.CachingDateFormatter)
    at ch.qos.logback.classic.pattern.DateConverter.convert(DateConverter.java:61)
    at ch.qos.logback.classic.pattern.DateConverter.convert(DateConverter.java:23)

通过加载ResourceBundle类将0x000000074bc00778锁定:

    "My-remoting-thread-5" #769 daemon prio=10 os_prio=0 tid=0x00007f941c011000 nid=0x17d1 runnable [0x00007f91df924000]
   java.lang.Thread.State: RUNNABLE
    at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
    at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
    at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
    at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:92)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:55)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2655)
    at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1511)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1475)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1429)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1429)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1371)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:900)
    at sun.util.resources.LocaleData$1.run(LocaleData.java:167)
    at sun.util.resources.LocaleData$1.run(LocaleData.java:163)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.util.resources.LocaleData.getBundle(LocaleData.java:163)
    at sun.util.resources.LocaleData.getDateFormatData(LocaleData.java:127)
    at java.text.DateFormatSymbols.initializeData(DateFormatSymbols.java:710)
    at java.text.DateFormatSymbols.<init>(DateFormatSymbols.java:145)
    at sun.util.locale.provider.DateFormatSymbolsProviderImpl.getInstance(DateFormatSymbolsProviderImpl.java:85)
    at java.text.DateFormatSymbols.getProviderInstance(DateFormatSymbols.java:364)
    at java.text.DateFormatSymbols.getInstance(DateFormatSymbols.java:340)
    at java.util.Calendar.getDisplayName(Calendar.java:2110)
    at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:1125)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:966)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
    at java.text.DateFormat.format(DateFormat.java:345)
    at ch.qos.logback.core.util.CachingDateFormatter.format(CachingDateFormatter.java:48)
    - locked <0x000000074bc00778> (a ch.qos.logback.core.util.CachingDateFormatter)
    at ch.qos.logback.classic.pattern.DateConverter.convert(DateConverter.java:61)

JDK版本为:1.8.0_152

登录中CachingDateFormatter的代码:

public final String format(long now) {
    synchronized (this) {
        if (now != lastTimestamp) {
            lastTimestamp = now;
            cachedStr = sdf.format(new Date(now));
        }
        return cachedStr;
    }
}

任何人都偶然知道这个问题是什么?

1 个答案:

答案 0 :(得分:0)

很可能有一个线程在此实例上持有锁,以防止其他实例使用它。

我建议使用DateTimeFormatter,该锁定不需要锁定,可以并发执行。