访问冲突 - 使用rxtx的java程序自动关闭

时间:2017-05-12 17:15:18

标签: serial-port thread-safety rxtx

抱歉英语。我在运行与USB调制解调器交互的Java程序时遇到问题,它使用线程并通过rxtx库建立与多达24个COM端口的通信,当我通过USB集线器连接24台调制解调器时,会发生错误。它自行关闭并生成以下.log文件(部分)

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000001800087dd, pid=6564, tid=0x00000000000017a8
#
# JRE version: Java(TM) SE Runtime Environment (8.0_112-b15) (build 1.8.0_112-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.112-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [rxtxSerial.dll+0x87dd]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

---------------  T H R E A D  ---------------

Current thread (0x0000000017667000):  JavaThread "Thread-32" [_thread_in_native, id=6056, stack(0x000000001e640000,0x000000001e740000)]

siginfo: ExceptionCode=0xc0000005, writing address 0x0000000000000100

Register to memory mapping:

RAX=0x0000000000000000 is an unknown value
RBX=0x00000000162e4ba0 is an unknown value
RCX=0x0000000000000002 is an unknown value
RDX=0x0000000000000000 is an unknown value
RSP=0x000000001e73eab0 is pointing into the stack for thread: 0x0000000017667000
RBP=0x000000001e73ed28 is pointing into the stack for thread: 0x0000000017667000
RSI=0x0000000016ae623a is an unknown value
RDI=0x00000000162e4d20 is an unknown value
R8 =0x0000000000000000 is an unknown value
R9 =0x0000000000000000 is an unknown value
R10=0x0000000000000006 is an unknown value
R11=0x0000000000000001 is an unknown value
R12=0x000000001e73ed30 is pointing into the stack for thread: 0x0000000017667000
R13=0x0000000019553998 is pointing into metadata
R14=0x000000001e73ed30 is pointing into the stack for thread: 0x0000000017667000
R15=0x0000000017667000 is a thread


Stack: [0x000000001e640000,0x000000001e740000],  sp=0x000000001e73eab0,  free space=1018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [rxtxSerial.dll+0x87dd]
C  [rxtxSerial.dll+0xaab4]
C  [rxtxSerial.dll+0x213d]
C  0x0000000002738a4b

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  gnu.io.RXTXPort.open(Ljava/lang/String;)I+0
j  gnu.io.RXTXPort.<init>(Ljava/lang/String;)V+125
j  gnu.io.RXTXCommDriver.getCommPort(Ljava/lang/String;I)Lgnu/io/CommPort;+78
j  gnu.io.CommPortIdentifier.open(Ljava/lang/String;I)Lgnu/io/CommPort;+171
j  tw.modem.Porta.abrePorta()V+11
j  tw.modem.Porta.run()V+50
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x0000000016a33000 JavaThread "Thread-41" [_thread_in_native, id=6436, stack(0x000000001ecf0000,0x000000001edf0000)]
  0x0000000016a32000 JavaThread "Thread-40" [_thread_in_native, id=6008, stack(0x000000001ebc0000,0x000000001ecc0000)]
  0x0000000016a31800 JavaThread "Thread-39" [_thread_in_native, id=676, stack(0x000000001e950000,0x000000001ea50000)]
  0x0000000016a30800 JavaThread "Thread-38" [_thread_in_native, id=6368, stack(0x0000000019190000,0x0000000019290000)]
  0x0000000016a30000 JavaThread "Thread-37" [_thread_in_native, id=7160, stack(0x000000001e750000,0x000000001e850000)]
  0x0000000016a2f000 JavaThread "Thread-36" [_thread_in_native, id=5372, stack(0x000000001e210000,0x000000001e310000)]
  0x0000000017665800 JavaThread "Thread-35" [_thread_in_native, id=3228, stack(0x00000000188b0000,0x00000000189b0000)]
  0x0000000016a2d800 JavaThread "Thread-33" [_thread_blocked, id=1060, stack(0x000000001e850000,0x000000001e950000)]
=>0x0000000017667000 JavaThread "Thread-32" [_thread_in_native, id=6056, stack(0x000000001e640000,0x000000001e740000)]
  0x0000000017666000 JavaThread "Thread-31" [_thread_blocked, id=3368, stack(0x000000001e430000,0x000000001e530000)]
  0x0000000017661800 JavaThread "Thread-30" [_thread_blocked, id=6312, stack(0x000000001e310000,0x000000001e410000)]
  0x0000000017662800 JavaThread "Thread-29" [_thread_blocked, id=2556, stack(0x000000001e0b0000,0x000000001e1b0000)]
  0x0000000017660000 JavaThread "Thread-28" [_thread_blocked, id=6584, stack(0x000000001dc60000,0x000000001dd60000)]
  0x0000000017663000 JavaThread "Thread-27" [_thread_blocked, id=748, stack(0x0000000019da0000,0x0000000019ea0000)]
  0x0000000017661000 JavaThread "Thread-26" [_thread_blocked, id=4080, stack(0x000000001c990000,0x000000001ca90000)]
  0x0000000017664000 JavaThread "Thread-25" [_thread_blocked, id=6452, stack(0x000000001dec0000,0x000000001dfc0000)]
  0x0000000017664800 JavaThread "Thread-24" [_thread_blocked, id=4544, stack(0x000000001db50000,0x000000001dc50000)]
  0x0000000016a21800 JavaThread "Image Animator 3" daemon [_thread_blocked, id=6328, stack(0x0000000019850000,0x0000000019950000)]
  0x0000000017626800 JavaThread "Timer-0" [_thread_blocked, id=6772, stack(0x00000000199b0000,0x0000000019ab0000)]
  0x00000000176c7800 JavaThread "TimerQueue" daemon [_thread_blocked, id=5760, stack(0x0000000019700000,0x0000000019800000)]
  0x00000000003be800 JavaThread "DestroyJavaVM" [_thread_blocked, id=3488, stack(0x0000000002350000,0x0000000002450000)]
  0x00000000177a9800 JavaThread "AWT-EventQueue-0" [_thread_blocked, id=424, stack(0x0000000019300000,0x0000000019400000)]
  0x000000001753b000 JavaThread "AWT-Windows" daemon [_thread_in_native, id=2300, stack(0x0000000018610000,0x0000000018710000)]
  0x0000000016b65800 JavaThread "AWT-Shutdown" [_thread_blocked, id=7152, stack(0x0000000018490000,0x0000000018590000)]
  0x0000000016b64800 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=3384, stack(0x00000000180c0000,0x00000000181c0000)]
  0x000000001697a800 JavaThread "Abandoned connection cleanup thread" daemon [_thread_blocked, id=5112, stack(0x0000000017380000,0x0000000017480000)]
  0x000000001683e000 JavaThread "Service Thread" daemon [_thread_blocked, id=6648, stack(0x0000000017040000,0x0000000017140000)]
  0x00000000167c5000 JavaThread "C1 CompilerThread2" daemon [_thread_blocked, id=7044, stack(0x0000000016e50000,0x0000000016f50000)]
  0x00000000167c4800 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=5560, stack(0x0000000016c00000,0x0000000016d00000)]
  0x0000000014f7a800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=3980, stack(0x0000000016300000,0x0000000016400000)]
  0x0000000014f78000 JavaThread "Attach Listener" daemon [_thread_blocked, id=4684, stack(0x00000000166b0000,0x00000000167b0000)]
  0x0000000014f74800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=5064, stack(0x0000000016530000,0x0000000016630000)]
  0x0000000014f5a800 JavaThread "Finalizer" daemon [_thread_blocked, id=4300, stack(0x0000000016430000,0x0000000016530000)]
  0x0000000014f13800 JavaThread "Reference Handler" daemon [_thread_blocked, id=1556, stack(0x0000000016170000,0x0000000016270000)]

Other Threads:
  0x0000000014f0b800 VMThread [stack: 0x0000000015f80000,0x0000000016080000] [id=3788]
  0x000000001686c000 WatcherThread [stack: 0x0000000017160000,0x0000000017260000] [id=6028]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None


---------------  S Y S T E M  ---------------

OS: Windows 7 , 64 bit Build 7601 (6.1.7601.23569)

CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, clmul, ht, tsc, tscinvbit

Memory: 4k page, physical 4104836k(1314976k free), swap 8207812k(4569232k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (25.112-b15) for windows-amd64 JRE (1.8.0_112-b15), built on Sep 22 2016 21:31:56 by "java_re" with MS VC++ 10.0 (VS2010)

函数abrePorta,负责打开报告中的COM端口并在此处。

private synchronized void abrePorta() {
        try {
            serialPort = (SerialPort) serialPortId.open("Porta", 6000);
            serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
            serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);
            at = new AtCommandPort(serialPort);
        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

任何人都知道它可能是什么?与港口建立通信是否有误?感谢

2 个答案:

答案 0 :(得分:0)

我在这里遇到了同样的问题。我发现C lib中的内存管理导致了这个问题。

答案 1 :(得分:0)

我解决了这个问题。通过替换用于64位操作系统的rxtxSerial64.dll。