[libvirt] libvirt(-java): How to make vm.getDomain().getJobInfo() thread safe?

Thomas Treutner thomas at scripty.at
Fri Sep 16 10:51:44 UTC 2011

On 09/16/2011 10:44 AM, Daniel P. Berrange wrote:
> On Wed, Sep 14, 2011 at 02:20:46PM +0200, Thomas Treutner wrote:
>> Of course, in my monitoring thread I'm checking in every monitoring
>> iteration if the domain object is not null, is still active, if the
>> jobInfo is available yet etc. But, as I can not synchronize with
>> vm.migrate(), there still a reasonable chance that migrate() just
>> invalidates the current domain while I'm accessing it, no matter
>> what I do.
> At the C level every API in libvirt is threadsafe. The only key point
> is that if you use objects (eg virDomainPtr) from multiple threads
> you ought to hold an extra reference on them (virDomainRef) per
> thread to ensure that one thread does not delete an object that is
> in use by the other thread.
> At the Java level, this reference handling ought to be working
> automatically so you wouldn't need todo anything special to safely
> do migration with 2 threads as you describe. So I don't really have
> any explanation for what you see.

I think that gave me a drift to the right direction, thanks. I'm using 
an additional, temporary domain (java) object in the monitoring thread 
now. The testing isn't running for a long time yet, but it looks 
promising. It's been a while since I poked around in libvirt-java, but 
could it be that per domain java object, a reference is held?


More information about the libvir-list mailing list