[Mulgara-general] Connections thread safe?

Andrae Muys andrae at netymon.com
Wed Feb 27 02:54:35 UTC 2008


On 27/02/2008, at 7:16 AM, 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.
>
> This is all working on the presumption that Sessions (which
> Connections wrap) are not thread safe.  They may be, but I don't think
> they are.

No, the underlying Sessions are not reentrant, although they are  
supposed to be thread-safe.  What I mean by this is, an attempt to  
access a Session concurrently by a second thread should result in an  
exception.  To what extent you can rely on this, given the number of  
edge-cases that have to be correctly handled, is another question.   
Still concurrent access doing more than throwing an exception is  
considered a bug.

Andrae


-- 
Andrae Muys
andrae at netymon.com
Senior RDF/SemanticWeb Consultant
Netymon Pty Ltd





More information about the Mulgara-general mailing list