[prev in list] [next in list] [prev in thread] [next in thread]
List: rxtx
Subject: Re: AW: [Rxtx] singleton design pattern [and synchronization]
From: "Dr. Douglas Lyon" <lyon () docjava ! com>
Date: 2006-01-20 8:04:09
Message-ID: p0602041dbff648d7fd78 () [192 ! 168 ! 1 ! 152]
[Download RAW message or body]
Hi All,
I have taken Brian's suggestion to heart:
public class SafeCommDriver {
private static RXTXCommDriver driver = null;
private SafeCommDriver() {
}
public synchronized static CommDriver getInstance() {
if (driver == null && NativeLibDetect.isLibInPath("rxtxSerial")) {
driver = new RXTXCommDriver();
driver.initialize();
}
return driver;
}
Does look like better code...(thanks Brian!).
I have heard of the multi-return
issue in the past and it concerns me that we have no clear resolution
on the matter. Perhaps it is too off-point for this list.
- Doug
>>Doug has been working hard on this off the list and I hope he will
>>share his work so far for further comments.
>
>
>I have an app that talks to VCR's using RS-422. It's multi-threaded
>and works well with java comm 2.0 but is not so friendly with RXTX
>(I've tried it with both 2.0 and 2.1). When Doug makes his code
>changes available I'd be happy to take them for spin and see if I
>run into any threading problems with it.
>
>BTW, The problems I had with RXTX were a) Not getting responses on
>windows (I suspect this has to do with the flow control setting bug
>that was recently reported.) b) The classpathx version of the
>java.comm libraries installed via fink on Mac OS X have some
>threading issues. My application throws a
>'java.lang.IllegalMonitorStateException: current thread not owner',
>which tells me something isn't synchronized correctly.
>
>@ Dr. Douglas Lyon
>
>>I did hear that some people don't like multiple exit points.
>
>Sorry, I wasn't make myself clear. I wasn't intending on starting a
>debate about multiple return statements. My point was really that
>the getInstance method is basically a lazy-initializer. So it's
>really only doing 2 things 1) Instantiating as instance if needed 2)
>return the instance. 3 returns seemed like a bit of overkill, that's
>all.
>
>Cheers
>Brian Schlining
>
>_______________________________________________
>Rxtx mailing list
>Rxtx@qbang.org
>http://mailman.qbang.org/mailman/listinfo/rxtx
_______________________________________________
Rxtx mailing list
Rxtx@qbang.org
http://mailman.qbang.org/mailman/listinfo/rxtx
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic