Concurrent Serial Port Usage

If we connect more than one thing to a serial port, we'll run into many PortInUseExceptions. We want to avoid that, otherwise our programs will be exiting when we don't want them to. (See Table 2-2.)

Table 2-2. Pros and Cons of Concurrent Usage

Solution

Create serial port inside each dependent object.

Create serial port outside of consuming objects.

Create single class that has control of all required actions of serial port.

Use a singleton of serial port inside each dependent object.

Use a singleton of serial ports inside a resource pool of all available serial ports.

Each class is self-contained.

Concurrent use limited to current thread. Closing of serial port can be done outside of individual objects.

Self-contained. Thread Safe. Closing of port managed inside of class.

Class is self-contained. Concurrent use is limited to JVM and is thread-safe. Closing of objects is done outside of individual objects.

Class is self-contained. Concurrent use is limited to JVM and is thread-safe. The closing of objects can be done outside of individual objects. Can request any available serial port system it can find.

Concurrent use likely; plus, application will throw PortInUseException. Closing of serial port has to be done via method call to invoking object.

Each class requires SerialPort to be sent in constructor. Not thread-safe.

Poor reuse.

Limited to single serial port regardless of com ID.

None.

0 0

Post a comment

  • Receive news updates via email from this site