|
From: Jacques B. <jac...@gm...> - 2003-12-09 13:26:41
|
Leif. >Of course simply restarting the JVM using the JVM would be the easiest. True, but does that have to be done manually, or by an external app like the wrapper only, or can I request the JVM to restart itself from within my app? The app must run completely unattended and also update itself unattended. Thanx for your other tips. java.net.URLClassLoader is what I used for my bootstrap class already. Jacques ----- Original Message ----- From: "Leif Mortenson" <le...@ta...> To: <wra...@li...> Sent: Tuesday, December 09, 2003 2:58 PM Subject: Re: [Wrapper-user] Restart VM : Jacques, : Of course simply restarting the JVM using the JVM would be the : easiest :-) But what : you asking is possible. I can't walk you through all of the steps. But : the basic idea is to : create a new class loader which loads your application. The class : loader works just like : any other object. When all of its references are gone it can be garbage : collected along : with any classes that it loaded. : : You would then repeat the process for your new invocation. : : Applications like Tomcat do this to make it possible to reload JSP : pages when : they have been modified. : : The difference between Tomcat and your application is that with : Tomcat, it is relatively : easy to know when it is safe to GC a particular classloader. All : threads that call into that : code and all references are controlled by Tomcat. : : Your application will most likely be launching several threads and : maybe even using : something like swing. Even you remove all reverence to the class : loader yourself, it : will not be Gced if even a single thread someplace is still referencing : any class or object : that was loaded with that class loader. : : Also remember that if you load class A in two different class : loaders they will not be : the same class even though they have the same name. Ie you can not : cast an instance : of one to the other. The only way to reference an object in another : class loader is by : using a class that was loaded from the same place. This will be true : with most of the : core java classes. : : If you feeling brave, a good place to start would be with the : java.net.URLClassLoader. : I have written applications that make use of multiple classloaders. : They can be quite : useful if really needed, but you will be surprised by all the little : issues that will come up. : : Cheers and Good luck. : Leif : : Jacques Bosch wrote: : : >Hi there Leif. : >I have managed to come right with writing a bootstrap class that first : >copies the update if there is one and then starts up the main app. It works : >beautifully. Thanx for the suggestion. : >This is probably the wrong place to be asking, but do you know if it is : >possible to unload the main app again without terminating the VM. I.e.The : >bootstrap class must still be loaded. : >What happens now, when using the wrapper: The app downloads the new jar, : >puts it in Updates folder, and signals for the wrapper to restart the VM. : >Wrapper restarts the VM starting with the bootstrap class, that then copies : >the update and starts up the app. : >But now I would love to have the same functionality even when the wrapper : >isn't used. I.e. The app, that was loaded with the bootstrap, downloads the : >new jar, and then some how indicates to the bootstrat that there is an : >update. The bootstrap unloads the app, removing the VM's lock on the file, : >copies the update, and starts the app up once more. : > : >Do you know if this is possible? : > : >Thanx for your help. : >Jacques : > : > : >----- Original Message ----- : >From: "Leif Mortenson" <le...@ta...> : >To: <wra...@li...> : >Sent: Monday, December 01, 2003 3:07 PM : >Subject: Re: [Wrapper-user] Restart VM : > : > : >: Jacques, : >: In that case, you may have to play with class loaders. You will : >: have a bootstrap : >: class whose job is to look in a upgrade directory when it first starts. : >: If there are any new : >: jars, they are moved into the current jars dir. The bootstrap class : >: then actually calls the : >: real main method of your application. : >: : >: I don't think the jars will be locked until after they are actually : >: accessed. So as long as : >: your bootstrap class is in its own stable and independent jar then this : >: should work. If not : >: then you will have to have your bootstrap class create a new class : >: loader, which in turn : >: builds up a classpath and so on. Classloaders can be a bit of a pain, : >: so hopefully the first : >: option will work. : >: : >: Be sure to post back with the results. : >: : >: Cheers, : >: Leif : >: : >: Jacques Bosch wrote: : >: : >: >Leif. The app is deployed with the Sun JVM and it also locks the jars. So : >my : >: >problem is that I cannot replace the old jar file with the new one while : >the : >: >VM is still running. : >: > : >: > : >: : >: : >: : >: : >: ------------------------------------------------------- : >: This SF.net email is sponsored by: SF.net Giveback Program. : >: Does SourceForge.net help you be more productive? Does it : >: help you create better code? SHARE THE LOVE, and help us help : >: YOU! Click Here: http://sourceforge.net/donate/ : >: _______________________________________________ : >: Wrapper-user mailing list : >: Wra...@li... : >: https://lists.sourceforge.net/lists/listinfo/wrapper-user : >: : >: : >: : > : > : > : >------------------------------------------------------- : >This SF.net email is sponsored by: IBM Linux Tutorials. : >Become an expert in LINUX or just sharpen your skills. Sign up for IBM's : >Free Linux Tutorials. Learn everything from the bash shell to sys admin. : >Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click : >_______________________________________________ : >Wrapper-user mailing list : >Wra...@li... : >https://lists.sourceforge.net/lists/listinfo/wrapper-user : > : > : > : : : : : ------------------------------------------------------- : This SF.net email is sponsored by: IBM Linux Tutorials. : Become an expert in LINUX or just sharpen your skills. Sign up for IBM's : Free Linux Tutorials. Learn everything from the bash shell to sys admin. : Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click : _______________________________________________ : Wrapper-user mailing list : Wra...@li... : https://lists.sourceforge.net/lists/listinfo/wrapper-user : : : |