title: JSSC serial connection set write timeout
body: <p>I need to write some byte to the serial connection. However I can not find something in <a href="http://code.google.com/p/java-simple-serial-connector/" rel="nofollow">JSSC</a> library to set a write timeout. I need this timeout because if I set the hardware flowcontrol and I remove the cable my application is stuck waiting the CTS signal.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried this workaround with Future object:</p>
  
  <pre><code>    ExecutorService executor = Executors.newSingleThreadExecutor();
      ...
      public synchronized void write(byte[] content, int timeout) throws InterruptedException, SerialPortException{
              long starttime = System.currentTimeMillis();
              Future&lt;Boolean&gt; future = executor.submit(new Callable&lt;Boolean&gt;() {
                  public Boolean call() throws Exception {
                      serialPort.writeBytes(content);
                      return new Boolean(true);
                  }
              });
              try {
                  future.get(timeout, TimeUnit.MILLISECONDS);
                  log.debug("Duration: {}",DurationFormatUtils.formatDuration(System.currentTimeMillis() - starttime, "mm:ss.SS"));
              } catch (ExecutionException e) {
                  throw new HardwareException(e.getMessage());
              } catch (TimeoutException e) {
                  throw new HardwareException("Impossibile scrivere nella porta seriale (timeout)");
              }
          }
  </code></pre>
  
  <p>But it doesn't work very well, it take 4s to write 550byte via COM port 256000 baud...</p>
  
  <p>Trying a direct write:</p>
  
  <pre><code>    public synchronized void write(byte[] content, int timeout) throws InterruptedException, SerialPortException{
          try {
              long starttime = System.currentTimeMillis();
              serialPort.writeBytes(content);
              log.debug("Duration: {}",DurationFormatUtils.formatDuration(System.currentTimeMillis() - starttime, "mm:ss.SS"));
          } catch (SerialPortException e) {
              throw new HardwareException(e.getMessage());
          }
      }
  </code></pre>
  
  <p>It took 0.5s as expected!</p>
  
  <p>The problem seems to be the "syncronized" keyword in the main method, why?</p>