I have a Java program that takes about an hour to run. While it is running, if I change the source code and recompile it, will this affect the above run?
|
If the "while it is running" is a requirement, you need to be looking at dynamic loading of class files. Application servers support this type of structure - after all, it is how you do a redeployment of an application without stopping and starting the server. You start getting things like How to dynamically reload classes when class files are changed in WebSphere Portlet Factory and designing the application correctly (see Dynamic Class Loading and Reloading in Java). Dynamic loading of classes isn't the best idea - especially if done frequently. The reason is that the class itself is loaded into permgen in the vm (this depends on the jvm (see when do classes in jars enter the PermGen) - repeatedly reloading a class means you will be leaking the memory of the unused classes. (See Classloader leaks: the dreaded "java.lang.OutOfMemoryError: PermGen space" exception - a bit dated, but still useful). This assumes you want to load it on the fly. If it is "I don't want to stop for an hour while I recompile" there are other solutions. A build shouldn't take an hour to build if you change one class file. In days of old, one used
It will only compile things that have changed. If you change one file, it only compiles one file. So, only build the .class you need, or the .jar you need rather than the entire project. If it isn't organized that way, organize it so that you can just compile the parts you need. This way, you won't need an hour to recompile everything - just a minute to recompile what you need. |
|||
|