[Mulgara-general] Connections thread safe?
Life is hard, and then you die
ronald at innovation.ch
Wed Feb 27 03:31:25 UTC 2008
On Tue, Feb 26, 2008 at 03:16:38PM -0600, Paul Gearon wrote:
> On Tue, Feb 26, 2008 at 1:32 PM, Alex Hall <alexhall at revelytix.com> wrote:
> > Are Connections in Mulgara thread-safe? I am writing an abstraction
> > layer on top of Mulgara to represent ontology models, and each "model"
> > needs to have a Connection to the server that it uses to execute queries
> > to get ontology metadata, list classes, etc.
> >
> > Since the ConnectionFactory caches the Connections that it creates, if
> > the models all share the same factory then they will wind up using the
> > same Connection object. This could possibly result in multiple,
> > overlapping commands being executed on the same session from different
> > threads. Is this OK, or should I ensure that each model gets its own
> > Connection instance?
>
> The plan was to use one factory per thread. However, now that you
> raise it, it sounds like a bad idea. I should probably put in some
> TLS so that a shared factory will hand out new Connections for new
> threads.
How about separating the concepts of factory and pooling: let the
ConnectionFactory be just that, a factory, which always creates a new
connection when asked, and create a ConnectionPool (that take a
ConnectionFactory as a parameter) which manages a pool of connections
and which uses a check-out/check-in approach (maybe use commons-pool
for this).
Cheers,
Ronald
More information about the Mulgara-general
mailing list