仅从jar文件运行时,新的org.json.JSONObject(String)无限期阻塞

问题描述 投票:0回答:1

我有一个SwingWorker后台线程,其中包含以下代码以执行请求并解析响应:

(new SwingWorker<Void, Void>() {
    @Override
    protected Void doInBackground() {
...
    HttpRequest listRequest = HttpRequest
        .newBuilder(url)
        .GET()
        .build();

    HttpResponse<String> listResponse = client
        .send(listRequest, HttpResponse.BodyHandlers.ofString());

    /* listResponse.body() is correct and can be printed/logged */

    JSONObject listing = new JSONObject(listResponse.body()); /* hangs when run from JAR */
...
    return null;
  }
}).execute();

org.json的版本是20190722(我也尝试过20800813),而JVM是Oracle HotSpot 12.0.1 2019-04-16(内部版本12.0.1 + 12)

maven编译器的源和目标在POM中设置为9。 (以及Eclipse中的Java-SE9。)

当我从eclipse运行代码时,它使用命令直接从目标类中启动它:

/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java \
  -Dfile.encoding=UTF-8 \
  -classpath \
    /Users/example/workspace/upload-client/target/classes:\
    /Users/example/.m2/repository/org/projectlombok/lombok/1.18.10/lombok-1.18.10.jar:\
    /Users/example/.m2/repository/org/json/json/20190722/json-20190722.jar \
  com.example.UploadClient

一切都很好,但是当我使用此经过稍微修改的命令从JAR加载它时:

/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java \
  -Dfile.encoding=UTF-8 \
  -jar ./target/upload-client-1.0.jar \
  com.example.UploadClient

它挂在JSONObject listing = new JSONObject(listResponse.body());行上。我已经在该行中插入了日志记录,以确定listResponse.body()如预期的那样返回了一个5k的正确json字符串。

从jar运行时,执行将在此行停止,并且不会继续。 Jstack输出在这里列出:

2019-10-22 13:37:55
Full thread dump Java HotSpot(TM) 64-Bit Server VM (12.0.1+12 mixed mode, sharing):

Threads class SMR info:
_java_thread_list=0x00007f9ac10242d0, length=18, elements={
0x00007f9ac0819000, 0x00007f9ac081c000, 0x00007f9ac0805800, 0x00007f9ac1803000,
0x00007f9ac1804800, 0x00007f9ac1808000, 0x00007f9ac1821000, 0x00007f9ac088f000,
0x00007f9ac010a000, 0x00007f9ac010c000, 0x00007f9abfa00800, 0x00007f9ac2011800,
0x00007f9ac0187000, 0x00007f9ac01b1000, 0x00007f9abfc2f000, 0x00007f9ac02f3800,
0x00007f9ac00da800, 0x00007f9ac19ce000
}

"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=0.62ms elapsed=127.37s tid=0x00007f9ac0819000 nid=0x3a03 waiting on condition  [0x000070000d2d1000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.ref.Reference.waitForReferencePendingList([email protected]/Native Method)
    at java.lang.ref.Reference.processPendingReferences([email protected]/Reference.java:241)
    at java.lang.ref.Reference$ReferenceHandler.run([email protected]/Reference.java:213)

"Finalizer" #3 daemon prio=8 os_prio=31 cpu=1.05ms elapsed=127.37s tid=0x00007f9ac081c000 nid=0x4903 in Object.wait()  [0x000070000d3d4000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait([email protected]/Native Method)
    - waiting on <no object reference available>
    at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:155)
    - locked <0x000000070055f0b0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:176)
    at java.lang.ref.Finalizer$FinalizerThread.run([email protected]/Finalizer.java:170)

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 cpu=0.26ms elapsed=127.36s tid=0x00007f9ac0805800 nid=0x3d07 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=31 cpu=1884.06ms elapsed=127.36s tid=0x00007f9ac1803000 nid=0x5603 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task

"C1 CompilerThread0" #8 daemon prio=9 os_prio=31 cpu=1066.76ms elapsed=127.36s tid=0x00007f9ac1804800 nid=0x5803 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task

"Sweeper thread" #9 daemon prio=9 os_prio=31 cpu=11.33ms elapsed=127.36s tid=0x00007f9ac1808000 nid=0xa603 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Service Thread" #10 daemon prio=9 os_prio=31 cpu=0.07ms elapsed=127.34s tid=0x00007f9ac1821000 nid=0x5a03 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Common-Cleaner" #11 daemon prio=8 os_prio=31 cpu=1.22ms elapsed=127.34s tid=0x00007f9ac088f000 nid=0xa303 in Object.wait()  [0x000070000dae9000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait([email protected]/Native Method)
    - waiting on <no object reference available>
    at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:155)
    - locked <0x000000070057a0f8> (a java.lang.ref.ReferenceQueue$Lock)
    at jdk.internal.ref.CleanerImpl.run([email protected]/CleanerImpl.java:148)
    at java.lang.Thread.run([email protected]/Thread.java:835)
    at jdk.internal.misc.InnocuousThread.run([email protected]/InnocuousThread.java:134)

"AppKit Thread" #12 daemon prio=5 os_prio=31 cpu=3875.45ms elapsed=127.25s tid=0x00007f9ac010a000 nid=0x307 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"AWT-Shutdown" #13 prio=5 os_prio=31 cpu=0.19ms elapsed=127.22s tid=0x00007f9ac010c000 nid=0x8c03 in Object.wait()  [0x000070000dc6f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait([email protected]/Native Method)
    - waiting on <no object reference available>
    at java.lang.Object.wait([email protected]/Object.java:326)
    at sun.awt.AWTAutoShutdown.run([email protected]/AWTAutoShutdown.java:291)
    - locked <0x000000070055f0f0> (a java.lang.Object)
    at java.lang.Thread.run([email protected]/Thread.java:835)

"AWT-EventQueue-0" #14 prio=6 os_prio=31 cpu=2127.72ms elapsed=126.82s tid=0x00007f9abfa00800 nid=0xd003 waiting on condition  [0x000070000e001000]
   java.lang.Thread.State: WAITING (parking)
    at jdk.internal.misc.Unsafe.park([email protected]/Native Method)
    - parking to wait for  <0x000000070058ae30> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park([email protected]/LockSupport.java:194)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await([email protected]/AbstractQueuedSynchronizer.java:2081)
    at java.awt.EventQueue.getNextEvent([email protected]/EventQueue.java:566)
    at java.awt.EventDispatchThread.pumpOneEventForFilters([email protected]/EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEventsForFilter([email protected]/EventDispatchThread.java:124)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy([email protected]/EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents([email protected]/EventDispatchThread.java:109)
    at java.awt.EventDispatchThread.pumpEvents([email protected]/EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.run([email protected]/EventDispatchThread.java:90)

"DestroyJavaVM" #15 prio=5 os_prio=31 cpu=173.20ms elapsed=126.82s tid=0x00007f9ac2011800 nid=0x1e03 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Java2D Queue Flusher" #16 daemon prio=10 os_prio=31 cpu=599.14ms elapsed=126.53s tid=0x00007f9ac0187000 nid=0x11e07 in Object.wait()  [0x000070000e104000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait([email protected]/Native Method)
    - waiting on <no object reference available>
    at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run([email protected]/OGLRenderQueue.java:205)
    - locked <0x000000070055f568> (a sun.java2d.opengl.OGLRenderQueue$QueueFlusher)
    at java.lang.Thread.run([email protected]/Thread.java:835)

"Java2D Disposer" #17 daemon prio=10 os_prio=31 cpu=0.94ms elapsed=126.47s tid=0x00007f9ac01b1000 nid=0x11717 in Object.wait()  [0x000070000e207000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait([email protected]/Native Method)
    - waiting on <no object reference available>
    at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:155)
    - locked <0x000000070055f768> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:176)
    at sun.java2d.Disposer.run([email protected]/Disposer.java:144)
    at java.lang.Thread.run([email protected]/Thread.java:835)

"TimerQueue" #22 daemon prio=5 os_prio=31 cpu=23.30ms elapsed=120.53s tid=0x00007f9abfc2f000 nid=0x15537 waiting on condition  [0x000070000e30a000]
   java.lang.Thread.State: WAITING (parking)
    at jdk.internal.misc.Unsafe.park([email protected]/Native Method)
    - parking to wait for  <0x0000000700551ee8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park([email protected]/LockSupport.java:194)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await([email protected]/AbstractQueuedSynchronizer.java:2081)
    at java.util.concurrent.DelayQueue.take([email protected]/DelayQueue.java:217)
    at javax.swing.TimerQueue.run([email protected]/TimerQueue.java:171)
    at java.lang.Thread.run([email protected]/Thread.java:835)

"SwingWorker-pool-1-thread-1" #23 daemon prio=5 os_prio=31 cpu=189.72ms elapsed=105.85s tid=0x00007f9ac02f3800 nid=0x7e4b waiting on condition  [0x000070000dd72000]
   java.lang.Thread.State: WAITING (parking)
    at jdk.internal.misc.Unsafe.park([email protected]/Native Method)
    - parking to wait for  <0x00000007005604b8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park([email protected]/LockSupport.java:194)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await([email protected]/AbstractQueuedSynchronizer.java:2081)
    at java.util.concurrent.LinkedBlockingQueue.take([email protected]/LinkedBlockingQueue.java:433)
    at java.util.concurrent.ThreadPoolExecutor.getTask([email protected]/ThreadPoolExecutor.java:1054)
    at java.util.concurrent.ThreadPoolExecutor.runWorker([email protected]/ThreadPoolExecutor.java:1114)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run([email protected]/ThreadPoolExecutor.java:628)
    at java.lang.Thread.run([email protected]/Thread.java:835)

"HttpClient-1-SelectorManager" #24 daemon prio=5 os_prio=31 cpu=38.46ms elapsed=105.78s tid=0x00007f9ac00da800 nid=0x1fc07 runnable  [0x000070000eb22000]
   java.lang.Thread.State: RUNNABLE
    at sun.nio.ch.KQueue.poll([email protected]/Native Method)
    at sun.nio.ch.KQueueSelectorImpl.doSelect([email protected]/KQueueSelectorImpl.java:122)
    at sun.nio.ch.SelectorImpl.lockAndDoSelect([email protected]/SelectorImpl.java:124)
    - locked <0x000000070f61cec0> (a sun.nio.ch.Util$2)
    - locked <0x000000070f61ce60> (a sun.nio.ch.KQueueSelectorImpl)
    at sun.nio.ch.SelectorImpl.select([email protected]/SelectorImpl.java:136)
    at jdk.internal.net.http.HttpClientImpl$SelectorManager.run([email protected]/HttpClientImpl.java:867)

"Attach Listener" #28 daemon prio=9 os_prio=31 cpu=0.97ms elapsed=0.10s tid=0x00007f9ac19ce000 nid=0x16007 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"VM Thread" os_prio=31 cpu=27.33ms elapsed=127.37s tid=0x00007f9abf908800 nid=0x3703 runnable  

"GC Thread#0" os_prio=31 cpu=24.36ms elapsed=127.38s tid=0x00007f9abf839000 nid=0x2d03 runnable  

"GC Thread#1" os_prio=31 cpu=18.07ms elapsed=105.83s tid=0x00007f9ac188b800 nid=0x28fb runnable  

"GC Thread#2" os_prio=31 cpu=22.84ms elapsed=105.83s tid=0x00007f9ac188e800 nid=0x7a0f runnable  

"GC Thread#3" os_prio=31 cpu=20.48ms elapsed=105.83s tid=0x00007f9ac19cf800 nid=0x7f07 runnable  

"GC Thread#4" os_prio=31 cpu=23.51ms elapsed=105.83s tid=0x00007f9ac288c800 nid=0x9407 runnable  

"GC Thread#5" os_prio=31 cpu=20.98ms elapsed=105.83s tid=0x00007f9abf97c000 nid=0x11213 runnable  

"G1 Main Marker" os_prio=31 cpu=0.23ms elapsed=127.38s tid=0x00007f9abf852000 nid=0x4f03 runnable  

"G1 Conc#0" os_prio=31 cpu=0.03ms elapsed=127.38s tid=0x00007f9abf852800 nid=0x3003 runnable  

"G1 Refine#0" os_prio=31 cpu=5.64ms elapsed=127.38s tid=0x00007f9abf8f3800 nid=0x4d03 runnable  

"G1 Refine#1" os_prio=31 cpu=2.59ms elapsed=105.82s tid=0x00007f9ac3059800 nid=0x8307 runnable  

"G1 Refine#2" os_prio=31 cpu=0.90ms elapsed=105.82s tid=0x00007f9ac2875800 nid=0x1090b runnable  

"G1 Young RemSet Sampling" os_prio=31 cpu=22.63ms elapsed=127.38s tid=0x00007f9abf8f4000 nid=0x3303 runnable  
"VM Periodic Task Thread" os_prio=31 cpu=86.51ms elapsed=127.34s tid=0x00007f9ac0019800 nid=0x5c03 waiting on condition  

JNI global refs: 113, weak refs: 252

欢迎提出任何建议。

java jvm jvm-hotspot org.json
1个回答
0
投票

它不会阻止。请注意,整个线程转储中没有doInBackground方法,SwingWorker线程池处于空闲状态。

[更有可能,代码抛出未捕获的异常或错误-可能是NoClassDefFoundError。当您以-jar身份启动应用程序时,类路径中必须缺少某些依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.