Overwriting class files

I have an app talking to a PLC which runs 24hours a day. Occasionally I need to update a small change to it. If it isn抰 a mission critical update I抦 happy to wait for the next standard restart.Is it OK to compile a new class file over the top of the current running one so it is available for the next restart? Or does Java perform some reloading / paging of the object.

[377 byte] By [QldKeva] at [2007-10-2 21:54:27]
# 1

> I have an app talking to a PLC which runs 24hours a

> day. Occasionally I need to update a small change to

> it. If it isn抰 a mission critical update I抦 happy

> to wait for the next standard restart.Is it OK to

> compile a new class file over the top of the current

> running one so it is available for the next restart?

> Or does Java perform some reloading / paging of the

> object.

I think that's the use of the xml bean mappings of j2ee. But I don't know if the system will even allow you to overwrite a running application.... why not create a batch or shell script to stop it, compile the code, then run it again, at least it'll be fast... :)

Herr_Fantastischa at 2007-7-14 1:10:24 > top of Java-index,Java Essentials,Java Programming...
# 2
> Is it OK to compile a new class file over the top of the current running one so it is available for the next restart?Yes, unless you (or your application manager) do tricky things with classloaders.
YAT_Archivista at 2007-7-14 1:10:24 > top of Java-index,Java Essentials,Java Programming...
# 3
The Instumentation API can be used to hotswap classes
IanSchneidera at 2007-7-14 1:10:24 > top of Java-index,Java Essentials,Java Programming...
# 4

Thanks for the feedback.

I can't stop and restart the process easy as it controls a full automated mill. To do a full stop we need to stop the mill from loading and wait for it to empty, (40 mins delay) then compile restart etc. Then we can start loading cane again.

I'll have a look into hot swapping; and may try a test local having an app running for a few days with a newer version of the class overwritten the original to see what happens.

QldKeva at 2007-7-14 1:10:24 > top of Java-index,Java Essentials,Java Programming...
# 5
You can probably overwrite the .class file but can you be sure it will ever get reloaded? This will only happen after the classloader that loaded it the first time exits.
ejpa at 2007-7-14 1:10:24 > top of Java-index,Java Essentials,Java Programming...
# 6

I normally override the classes by compuiling the source while application is still running and it never effected the application if the classes that are overridden have already been laded in the application.

But that migh depend on the JVM that you are using.

I think it is better to use hot swapping. Or you can modify the script or write a loader for the application which copy the classes from the build destination to the runtime classpath just before the execution of the application.

LRMKa at 2007-7-14 1:10:24 > top of Java-index,Java Essentials,Java Programming...