Without I/O, to either files or some other local, non-shareable resource, then it's a system dependant thing. You'd have to write some piece of native code that makes use of Semaphores to do the job. It's a weird thing to do, but, knock yerself out ;-)
Another solution is to use a file, containing a unique identifier which would be created by a ClassLoader (check the class java.rmi.dgc.VMID). The first ClassLoader to create the file will be the one able to load the Class. Of course, if this ClassLoader is terminated(JVM shutdown), it must DELETE the file. Errors (not Exceptions) will prevent every JVM from loading the class altogether. The server socket is the best solution I know of. It of course involves I/O. But it's very simple I/O, and very basic, and computationally inexpensive. It's also one that will probably work on most AppServers (altough it seems you're building a stand-alone application). My 2c, Juan Pablo Lorandi Chief Software Architect Code Foundry Ltd. [EMAIL PROTECTED] Barberstown, Straffan, Co. Kildare, Ireland. Tel: +353-1-6012050 Fax: +353-1-6012051 Mobile: +353-86-2157900 www.codefoundry.com > -----Original Message----- > From: A mailing list for Enterprise JavaBeans development > [mailto:[EMAIL PROTECTED]] On Behalf Of Keith Sterling > Sent: Wednesday, May 22, 2002 4:58 PM > To: [EMAIL PROTECTED] > Subject: Re: Off Topic : ClassLoaders > > > What you are asking for is close to impossible. Separate VMs > are almost always likely to be completely separate > applications and therefore have their own address space and process > > There are 2 possibilities I can think of. > > a) Write you own class loader that does process to process > communication, possibly UDP broadcast, which if picked up by > all other VM class loaders can check to see if they have > loaded the class already. You will definitely have problems > with this, as UDP is unreliable, and what happens if the > class is loaded at the same time by 2 VMs > > b) Have your class grab a server port, ( one which is > numbered less than < 1024 ). As only one process can have > access to a server port, the first class to grab it wins, any > other class loaded would get a socket error and then you > could terminate you application gracefully. This would not > need a Class Loaded writing of much logic > > keith > > -------------------------------------------------------------- > ----------- > Keith Sterling > Jacobs Rimell > VP of Engineering > Jacobs Rimell Ltd > 24 Chiswell St > London EC1Y 4TY > Tel : +44 207 786 4000 > Mob : +44 7771 597 630 > Fax : +44 207 786 4004 > MSN : [EMAIL PROTECTED] > http://www.jacobsrimell.com > -------------------------------------------------------------- > ----------- > IMPORTANT NOTICE: > This email is confidential, may be legally privileged, and is > for the intended recipient only. If you are not the intended > recipient, please inform the sender and delete the email immediately. > WARNING: > It is impossible to guarantee the content of this message > when it is delivered across the internet, therefore the > sender accepts no liability for any claims arising from the > information contained. > > > > > -----Original Message----- > > From: Ramakrishna N [mailto:[EMAIL PROTECTED]] > > Sent: 22 May 2002 16:42 > > To: [EMAIL PROTECTED] > > Subject: Off Topic : ClassLoaders > > > > Hi, > > This is an off topic suggestion that I am seeking but its urgent > > and so I am posting it here. > > I want only one Instance of a particular Class to be > running across > > multiple VMs. I mean if I am executing a class in one of > the VMs then If I > > say run the same Class in another VM of the same machine it > should not > > run. > > How do I achieve this behaviour ? > > Currently we have a configuration xml file where in the > Application > > registers when it has opened and registers again when it > has successfully > > closed so that in between if I try to open the application > in another VM > > the > > application first reads the configuration xml and > understands that one > > istance of the application is running and so it exits. > > I would like to achieve it through ClassLoaders. Say custom > > ClassLoaders. I am sure there should be a way to achieve > this without > > doing > > any I/O operations like opening a socket when the > application starts.. > > Any help on this would be of great help. Thanks in advance. > > > > Thanks & Regards, > > kris > > > > > ====================================================================== > > ==== > > = > > To unsubscribe, send email to [EMAIL PROTECTED] and > include in the > > body > > of the message "signoff EJB-INTEREST". For general help, > send email to > > [EMAIL PROTECTED] and include in the body of the message "help". > > ============================================================== > ============= > To unsubscribe, send email to [EMAIL PROTECTED] and > include in the body of the message "signoff EJB-INTEREST". > For general help, send email to [EMAIL PROTECTED] and > include in the body of the message "help". > > =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
