Re: Two Services trying to load a System library in same JVM

Francisco Albasini Mourão <[email protected]> Tue, 8 Jul 2008 17:29:26 +0100
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
Thanx for the reply Gregg.
Yes. I'm using com.sun.jini.start to start the services.
This application is launching other services that are not MonitorService's. In fact, it could be launched without any MonitorService instance.
Building a new start.jar with things specific for it would make me loose modularity: 1) MonitorService would only run with this specific new start.jar 2) start.jar always used as a common package to start the services is now replaced for a specific jar to run MonitorServices..

Although, if there is no alternative...
 

-----Original Message-----
From: Gregg Wonderly [mailto:[email protected]] 
Sent: terça-feira, 8 de Julho de 2008 16:57
To: Francisco Albasini Mourão
Cc: [email protected]
Subject: Re: Two Services trying to load a System library in same JVM

Francisco Mourao wrote:
> Hi there,
> I have a monitor application that launches in the same JVM two instances of
> the same service each one monitoring a serial port. Namely, Monitor1 and
> Monitor2 are two instances of same service MonitorService with entries
> name=M1 and name=M2 respectively.
> 
> The problem is that MonitorService tries to load a system library with
> System.loadLibrary(...). The first instance to be initialized loads
> successfully but when the second service tries to load the library an
> exception is thrown saying that the library is already loaded. 
> 
> This must be a very common problem I suppose. So I think there must be some
> work around for this. Or not? 
> 
> I didn't want to launch a VM for each instance of MonitorService... i can
> have up to  20 instances...

The easiest thing to do is build a new start.jar that includes a class-path 
reference to the serial comms library's jar.  Then, it will be loaded once, from 
the system classloader, instead of from each services preferred classloader.

I am assuming you are using com.sun.jini.start to start your services.

Gregg Wonderly

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]