本文介绍: 写这篇文章时是 2023-02-07,先说环境:JDK和Tomcat都是下载最新的(修订号),恰恰是因为这个原因导致启动失败堆栈如下错误原因是JDK使用cgroupv2来调用资源限制功能,但Linux内核4.5才支持cgroupv2,导致了错误的发生。我感觉这是jdkbug没有正确判断系统使用的是cgroupv1还是cgroupv2jdk换成1.8.0_351就好了,不一定是这个版本,去到jdk.internal.platform.Metrics里面使用的是cgroupv1就可以

写这篇文章时是 2023-02-07,先说环境

JDK和Tomcat都是下载最新的(修订号),恰恰是因为这个原因导致启动失败堆栈如下

07-Feb-2023 22:40:18.345 严重 [main] org.apache.tomcat.util.digester.Digester.startElement Begin event threw error
	java.lang.InternalError: java.lang.reflect.InvocationTargetException
		at jdk.internal.platform.Metrics.systemMetrics(Metrics.java:67)
		at jdk.internal.platform.Container.metrics(Container.java:42)
		at sun.management.OperatingSystemImpl.<init&gt;(OperatingSystemImpl.java:181)
		at sun.management.ManagementFactoryHelper.getOperatingSystemMXBean(ManagementFactoryHelper.java:106)
		at java.lang.management.PlatformComponent$7.getMXBeans(PlatformComponent.java:157)
		at java.lang.management.PlatformComponent.getMXBeans(PlatformComponent.java:377)
		at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:472)
		at org.apache.tomcat.util.modeler.Registry.getMBeanServer(Registry.java:449)
		at org.apache.catalina.mbeans.MBeanUtils.createServer(MBeanUtils.java:581)
		at org.apache.catalina.mbeans.MBeanUtils.<clinit>(MBeanUtils.java:77)
		at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.<clinit>(GlobalResourcesLifecycleListener.java:68)
		at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
		at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
		at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
		at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
		at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:115)
		at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1235)
		at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:510)
		at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
		at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1341)
		at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)
		at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
		at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:507)
		at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:867)
		at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:796)
		at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142)
		at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
		at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:644)
		at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1496)
		at org.apache.catalina.startup.Catalina.load(Catalina.java:618)
		at org.apache.catalina.startup.Catalina.load(Catalina.java:669)
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
		at java.lang.reflect.Method.invoke(Method.java:498)
		at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:307)
		at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:477)
	Caused by: java.lang.reflect.InvocationTargetException
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
		at java.lang.reflect.Method.invoke(Method.java:498)
		at jdk.internal.platform.Metrics.systemMetrics(Metrics.java:63)
		... 36 more
	Caused by: java.lang.ExceptionInInitializerError
		at jdk.internal.platform.CgroupSubsystemFactory.create(CgroupSubsystemFactory.java:95)
		at jdk.internal.platform.CgroupMetrics.getInstance(CgroupMetrics.java:169)
		... 41 more
	Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
		at jdk.internal.platform.cgroupv2.CgroupV2Subsystem.initSubsystem(CgroupV2Subsystem.java:73)
		at jdk.internal.platform.cgroupv2.CgroupV2Subsystem.<clinit>(CgroupV2Subsystem.java:44)
		... 43 more
Exception in thread "main" java.lang.InternalError: java.lang.reflect.InvocationTargetException
	at jdk.internal.platform.Metrics.systemMetrics(Metrics.java:67)
	at jdk.internal.platform.Container.metrics(Container.java:42)
	at sun.management.OperatingSystemImpl.<init>(OperatingSystemImpl.java:181)
	at sun.management.ManagementFactoryHelper.getOperatingSystemMXBean(ManagementFactoryHelper.java:106)
	at java.lang.management.PlatformComponent$7.getMXBeans(PlatformComponent.java:157)
	at java.lang.management.PlatformComponent.getMXBeans(PlatformComponent.java:377)
	at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:472)
	at org.apache.tomcat.util.modeler.Registry.getMBeanServer(Registry.java:449)
	at org.apache.catalina.mbeans.MBeanUtils.createServer(MBeanUtils.java:581)
	at org.apache.catalina.mbeans.MBeanUtils.<clinit>(MBeanUtils.java:77)
	at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.<clinit>(GlobalResourcesLifecycleListener.java:68)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:115)
	at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1235)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1341)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:507)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:867)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:796)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:644)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1496)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:618)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:669)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:307)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:477)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at jdk.internal.platform.Metrics.systemMetrics(Metrics.java:63)
	... 36 more
Caused by: java.lang.ExceptionInInitializerError
	at jdk.internal.platform.CgroupSubsystemFactory.create(CgroupSubsystemFactory.java:95)
	at jdk.internal.platform.CgroupMetrics.getInstance(CgroupMetrics.java:169)
	... 41 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
	at jdk.internal.platform.cgroupv2.CgroupV2Subsystem.initSubsystem(CgroupV2Subsystem.java:73)
	at jdk.internal.platform.cgroupv2.CgroupV2Subsystem.<clinit>(CgroupV2Subsystem.java:44)
	... 43 more

错误原因是JDK使用cgroupv2来调用资源限制功能,但Linux内核4.5才支持cgroupv2,导致了错误的发生。
我感觉这是jdk的bug没有正确的判断系统使用的是cgroupv1还是cgroupv2

jdk换成1.8.0_351就好了,不一定是这个版本,去到jdk.internal.platform.Metrics里面使用的是cgroupv1就可以

    static Metrics systemMetrics() {
        try {
            Class var0 = Class.forName("jdk.internal.platform.cgroupv1.Metrics");
            Method var1 = var0.getMethod("getInstance");
            return (Metrics)var1.invoke((Object)null);
        } catch (ClassNotFoundException var2) {
            return null;
        } catch (ReflectiveOperationException var3) {
            throw new InternalError(var3);
        }
    }

原文地址:https://blog.csdn.net/qq_42814833/article/details/128935027

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_36806.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注