为什么 java newInstance 挂在 getDeclaredConstructors0 处?

2023-12-22

我们使用mozlia rhino生成动态类,然后通过自定义类加载器加载JsClass,如下所示

DynamicClassLoader loader = new DynamicClassLoader(JavaScriptFactory.class.getClassLoader());
Class<?> jsClass = loader.loadClass("D://","com.huawei.xxx");
jsClass.newInstance();

正如你所看到的,每个JsClass都有一个单独的类加载器,当用户修改js时,我们也会通过这段代码重新加载JsClass,

现在,我们面临一个问题,当调用 jsClass.newInstance() 时,某些线程在 getDeclaredConstructors0 处挂起很长一段时间(3s-1000s),通常应该小于 10ms。有人可以告诉我可能的原因吗?非常感谢!

JDK:1.8.0.60

Tomcat: 7.0.59

JvmArgs:

-Dnop -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -DDN=mateinfo_app -server -Duser.timezone=GMT -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=80 -XX:+DisableExplicitGC -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:+PrintGCDetails -Xloggc:/opt/mateinfo/logs/app/tomcat-gc-20160601-233343.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/mateinfo/logs/app/oom-20160601-233343.bin -XX:OnOutOfMemoryError=./deal-oom.sh -Xms3260m -Xmx3260m -Xmn800m -XX:MetaspaceSize=800m -XX:MaxMetaspaceSize=800m -XX:SurvivorRatio=16 -XX:+OptimizeStringConcat -Xverify:all -Dsoapui.log4j.config=/opt/mateinfo/app/lib/log4j.properties -Dlog4j.ignoreTCL=true -XX:-OmitStackTraceInFastThrow -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8050 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs=/opt/mateinfo/app/endorsed -classpath /opt/mateinfo/app/bin/bootstrap.jar:/opt/mateinfo/app/bin/tomcat-juli.jar -Dcatalina.base=/opt/mateinfo/app -Dcatalina.home=/opt/mateinfo/app -Djava.io.tmpdir=/opt/mateinfo/app/temp org.apache.catalina.startup.Bootstrap start

线程转储:

----------------- 7123 -----------------
0x00007f9d44cdc6d5       __pthread_cond_wait + 0xc5
0x00007f9d43cc157c       _ZN15JvmtiRawMonitor11SimpleEnterEP6Thread + 0xdc
0x00007f9d43cc1c07       _ZN15JvmtiRawMonitor9raw_enterEP6Thread + 0xd7
0x00007f9d43c9a2ed      _ZN8JvmtiEnv15RawMonitorEnterEP15JvmtiRawMonitor + 0xad
0x00007f9d429c4df8       debugMonitorEnter + 0x38
0x00007f9d429b1451      event_callback + 0x2e1
0x00007f9d429b1e8e      cbClassPrepare + 0x8e
0x00007f9d43cb0beb      _ZN11JvmtiExport18post_class_prepareEP10JavaThreadP5Klass + 0x15b
0x00007f9d43b59f31       _ZN13InstanceKlass15link_class_implE19instanceKlassHandlebP6Thread + 0x3f1
0x00007f9d43b5a0d4      _ZN13InstanceKlass10link_classEP6Thread + 0x54
0x00007f9d43c3ec49       _ZL33get_class_declared_methods_helperP7JNIEnv_P7_jclasshbP5KlassP6Thread + 0xc9
0x00007f9d43c3f28e       JVM_GetClassDeclaredConstructors + 0xce

"app-JavaScriptFactory-7-thread-1" #41621 prio=5 os_prio=0 tid=0x00007f9d1d7f9800 nid=0x1bd3 runnable [0x00007f9c8040e000]
   java.lang.Thread.State: RUNNABLE
         at java.lang.Class.getDeclaredConstructors0(Native Method)
         at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
         at java.lang.Class.getConstructor0(Class.java:3075)
         at java.lang.Class.newInstance(Class.java:412)
         at com.huawei.sdm.integration.message.runtime.handler.script.JsBeanGenerateRunner.excute(JsBeanGenerateRunner.java:82)
         at com.huawei.mateinfo.context.support.CommonCallable.call(CommonCallable.java:31)
         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
         at java.lang.Thread.run(Thread.java:745)

GCLog:

{Heap before GC invocations=331320 (full 1587):
par new generation   total 773696K, used 732120K [0x00000006f4400000, 0x0000000726400000, 0x0000000726400000)
  eden space 728192K, 100% used [0x00000006f4400000, 0x0000000720b20000, 0x0000000720b20000)
  from space 45504K,   8% used [0x0000000723790000, 0x0000000723b66170, 0x0000000726400000)
  to   space 45504K,   0% used [0x0000000720b20000, 0x0000000720b20000, 0x0000000723790000)
concurrent mark-sweep generation total 2519040K, used 2123204K [0x0000000726400000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace       used 341907K, capacity 402760K, committed 687488K, reserved 1640448K
  class space    used 38870K, capacity 47018K, committed 95616K, reserved 1048576K
2016-05-31T12:47:08.303+0000: 550384.634: [GC (GCLocker Initiated GC) 2016-05-31T12:47:08.303+0000: 550384.634: [ParNew: 732120K->2438K(773696K), 0.0228934 secs] 2855324K->2125771K(3292736K), 0.0231999 secs] [Times: user=0.07 sys=0.00, real=0.03 secs]
Heap after GC invocations=331321 (full 1587):
par new generation   total 773696K, used 2438K [0x00000006f4400000, 0x0000000726400000, 0x0000000726400000)
  eden space 728192K,   0% used [0x00000006f4400000, 0x00000006f4400000, 0x0000000720b20000)
  from space 45504K,   5% used [0x0000000720b20000, 0x0000000720d81bc8, 0x0000000723790000)
  to   space 45504K,   0% used [0x0000000723790000, 0x0000000723790000, 0x0000000726400000)
concurrent mark-sweep generation total 2519040K, used 2123332K [0x0000000726400000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace       used 341907K, capacity 402760K, committed 687488K, reserved 1640448K
  class space    used 38870K, capacity 47018K, committed 95616K, reserved 1048576K
}
2016-05-31T12:47:08.334+0000: 550384.665: [GC (CMS Initial Mark) [1 CMS-initial-mark: 2123332K(2519040K)] 2135637K(3292736K), 0.0151574 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
2016-05-31T12:47:08.349+0000: 550384.681: [CMS-concurrent-mark-start]
{Heap before GC invocations=331321 (full 1588):
par new generation   total 773696K, used 730630K [0x00000006f4400000, 0x0000000726400000, 0x0000000726400000)
  eden space 728192K, 100% used [0x00000006f4400000, 0x0000000720b20000, 0x0000000720b20000)
  from space 45504K,   5% used [0x0000000720b20000, 0x0000000720d81bc8, 0x0000000723790000)
  to   space 45504K,   0% used [0x0000000723790000, 0x0000000723790000, 0x0000000726400000)
concurrent mark-sweep generation total 2519040K, used 2123332K [0x0000000726400000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace       used 341907K, capacity 402760K, committed 687488K, reserved 1640448K
  class space    used 38870K, capacity 47018K, committed 95616K, reserved 1048576K
2016-05-31T12:47:09.419+0000: 550385.751: [GC (Allocation Failure) 2016-05-31T12:47:09.419+0000: 550385.751: [ParNew: 730630K->11995K(773696K), 0.0311341 secs] 2853963K->2135459K(3292736K), 0.0314510 secs] [Times: user=0.10 sys=0.00, real=0.03 secs]
Heap after GC invocations=331322 (full 1588):
par new generation   total 773696K, used 11995K [0x00000006f4400000, 0x0000000726400000, 0x0000000726400000)
  eden space 728192K,   0% used [0x00000006f4400000, 0x00000006f4400000, 0x0000000720b20000)
  from space 45504K,  26% used [0x0000000723790000, 0x0000000724346f10, 0x0000000726400000)
  to   space 45504K,   0% used [0x0000000720b20000, 0x0000000720b20000, 0x0000000723790000)
concurrent mark-sweep generation total 2519040K, used 2123463K [0x0000000726400000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace       used 341907K, capacity 402760K, committed 687488K, reserved 1640448K
  class space    used 38870K, capacity 47018K, committed 95616K, reserved 1048576K
}

看起来应用程序正在调试器下运行。 Thread Dump 表示线程挂在 JDWP 代理内部。

尝试禁用调试器。或者,您可以通过添加以下代理选项来打开 JDWP 日志记录:

logfile=/path/to/jdwp.log,logflags=255
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 java newInstance 挂在 getDeclaredConstructors0 处? 的相关文章

  • 切换大小写错误。用于 Mac 上 Android 开发的 Eclipse IDE:将工作区合规性更改为 JRE 1.7

    当尝试在 android 项目中使用带有 switch string 的 Switch Case 时 我在 eclipse IDE 中收到错误消息 将工作区合规性更改为 JRE1 7 对于低于 1 7 的源级别 无法打开字符串类型的值 仅允
  • Flink Kafka - 如何使应用程序并行运行?

    我正在 Flink 中创建一个应用程序 读取某个主题的消息 对其进行一些简单的处理 将结果写入不同的主题 我的代码确实有效 然而它不并行运行我怎么做 看来我的代码只在一个线程 块上运行 在 Flink Web 仪表板上 应用程序进入运行状态
  • 如何按出现顺序创建 Java 文档?

    我有一个非常大的 java 类文件 其中有很多成员 如何为此创建 HTML 文档 以便它按出现顺序显示成员 而不按成员类型排序 方法 常量和变量 例如 如果我的 Java 代码是 private int typeOfAction 1 not
  • 将音频从 PC 传输到智能手机?

    2016 年圣诞节 我和我爸爸想用灯光和灯光为我们的社区举办一场灯光秀music We have the lights set up but the music is a problem We don t want to put huge
  • Spring:url 无法正确解析链接

    尽管我对 Java 有丰富的经验 但我对 Spring 框架和 Web 应用程序还很陌生 当我在本地 tomcat 服务器上运行我的网站时 URL 为 http localhost 8080 myApp 现在 请求映射将我委托到我的主页 R
  • Spring 3.1 Java配置和内部bean

    Bean public TimedRepository timedRepository RealRepository repo return new TimedRepository repo timer Adds some metrics
  • 在 Java 中使用并行性会使程序变慢(慢四倍!!!)

    我正在编写共轭梯度方法实现 我使用 Java 多线程进行矩阵反向替换 使用CyclicBarrier CountDownLatch 进行同步 为什么同步线程需要这么长时间 还有其他方法吗 代码片段 private void syncThre
  • 如何从 Android 服务获取应用程序上下文?

    我有一个正在运行并监听麦克风输入的 Android 服务 我希望它在满足特定条件时启动一项活动 为了创建意图 我需要应用程序上下文 我怎么才能得到它 Intent i new Intent ctx SONR class i addFlags
  • 在 Volley 中更新 UI 最有效的方法是什么

    最近我在 android 中使用 Volley 库 它工作得很好 但我想知道更新 UI 的最有效方法 我有一个包含所有 Volley 方法的 Utils 类 现在我传递了所有视图将作为参数更新 但我读到我可以在活动中实现侦听器 然后将它们作
  • 如何在 Spring Security 中创建自定义身份验证过滤器?

    我正在尝试创建一个自定义 Spring Security 身份验证过滤器以实现自定义身份验证方案 我花了几个小时阅读 Spring Security 但我找到的所有指南都解释了如何配置基本设置 我正在尝试编写自定义设置 但无法找到有关如何执
  • 如何生成0-8范围内除一个特定数字之外的随机数?

    我正在尝试开发 Tic Tac Toe 游戏 其中玩家 1 将单击一个按钮放置 X 稍后玩家 2 计算机 将在第一步中随机将 O 放置到其他按钮 为此 我需要创建一个随机数0 8 之间 除了玩家 1 点击的那个之外 我正在使用以下代码来生成
  • 更改 Java 字符串中的日期格式

    I ve a String代表一个日期 String date s 2011 01 18 00 00 00 0 我想将其转换为Date并将其输出到YYYY MM DD format 2011 01 18 我怎样才能实现这个目标 好的 根据我
  • Android O - 通知通道和NotificationCompat

    我无法改变这种感觉 Android 开发人员再次提出了一些新东西 却让每个人都对他们如何看待该功能的使用一无所知 我说的是 Android O 中的通知通道 多年来 我一直使用兼容性支持库来避免处理特定平台的细节 即 Notificatio
  • 本机查询 (JPA) 未重置并返回相同的旧结果

    我有一个本机 sql 查询如下 for init i 0 i lt 2 i String sql Select from accounts where id Query query em createNativeQuery sql Acco
  • String.substring 在 Java 中到底做了什么?

    我一直想如果我这样做String s Hello World substring 0 5 然后我就得到一个新字符串s Hello Java API 文档中也记录了这一点 返回一个新字符串 该字符串是该字符串的子字符串 但当我看到下面两个链接
  • Java中对象类的继承

    当我读java书时 我遇到了 每个类都扩展类 Object 但是如果想要 B 类扩展 A 类 但是 B 类现在将具有多重继承 一个来自 Object 类 一个来自 A 类 如何解决冲突 谁能解释一下吗 它是多级继承 而不是多重 class
  • Java 8 Streams - 嵌套映射到列表

    firstlist stream map x gt return secondList stream map y gt return a string collect Collectors toList Output I need Get
  • 使用可变参数绘制星形

    我的任务是编写程序 允许用户绘制星星 星星的大小和手臂数量可能不同 当我处理基本星时 我使用 GeneralPath 和点表进行处理 int xPoints 55 67 109 73 83 55 27 37 1 43 int yPoints
  • 如何在android中动态创建按钮?

    我想创建一个这样的页面 这 7 个按钮已经存在 但如果用户想添加更多类别 按钮 那么他可以使用 按钮并使用删除 按钮 有制作这个的想法或教程吗 创建 删除按钮onClick of button and button如下 public voi
  • 为什么 pagefactory 类在从另一个类初始化时返回 null

    在我的测试课上 我有DesiredCapabilities为 Appium 测试设置 在该课程中 我初始化了 BasePage 课程pagefactory元素 当我运行测试时 它按预期工作 现在 我尝试将 DesiredCapability

随机推荐