Hello ALL!
I wrote a simple java program to test an ibm communication api implementation. But it throws IllegalMonitorStateException when I trying to close com port on RedHat Linux 7.3. Please comment this situation if you can.
This is a program:
import java.io.*;
import java.util.*;
import javax.comm.*;
public class Relay {
static final String comPortName = "COM1";
static final String toRealy = "BLABLABLA";
public static void main( String[] argv ) {
try {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = getCommPortIdentifierByPortNumber( comPortName, portList );
SerialPort serialPort = (SerialPort) portId.open( "Relay", 30000 ); // 30 secs timeout
// System.out.println( "Sleep before closing 1 sec." );
// Thread.sleep( 1000 );
// System.out.println( "About to close serial port." );
serialPort.close();
} catch( Throwable e ) {
e.printStackTrace();
}
}
protected static CommPortIdentifier getCommPortIdentifierByPortNumber( String strPort, Enumeration portList ) throws IllegalArgumentException {
while( portList.hasMoreElements() ) {
CommPortIdentifier cpi = (CommPortIdentifier) portList.nextElement();
if( cpi.getName().equalsIgnoreCase( strPort ) == true ) return cpi;
}
throw new IllegalArgumentException( "Invalid port: " + strPort );
}
}
This program throws following exception:
java.lang.IllegalMonitorStateException
at java.lang.Object.notify(Native Method)
at com.ibm.comm.NSSerialPort$SerialEventDeliveryThread.prepareToStop(NSSerialPort.java:1275)
at com.ibm.comm.NSSerialPort.close(NSSerialPort.java:240)
at Relay.main(Relay.java:18)
P.S.I found in an archive
http://www-106.ibm.com/developerwork...ad=5511&cat=10 the same question but without answer