jdog456 / java-simple-serial-connector

Automatically exported from code.google.com/p/java-simple-serial-connector
0 stars 0 forks source link

waitBytesWithTimeout() silently disposes of InterruptedException #50

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This one is pretty difficult to reproduce, but in our case we have one thread 
that constantly reads from the serial port and the user can cancel reading on 
EDT. 

When the user cancels reading, the thread is cancelled using Future.cancel() 
method. In rare cases this happens in waitBytesWithTimeout() method while 
thread is sleeping. At this point InterruptedException is thrown and it is 
silently disposed of.
This results in thread not being cancelled.

I suggest replacing this whole block:
try {
                Thread.sleep(0, 100);//Need to sleep some time to prevent high CPU loading
            }
            catch (InterruptedException ex) {
                //Do nothing
            }

with the following line:
Thread.yield();

Original issue reported on code.google.com by etsi...@gmail.com on 11 Sep 2013 at 2:22