How hot deployment works internally?
Asked Answered
C

1

13

I am using eclipse server capability for hot code deployment. Using tomcat as web server. But i am not sure how it works. I have my own understanding how it must be working internally.

My understanding :- When developer make the changes in code(say class Employee), Eclipse will place/publish the modified compiled class at right location(must be specific web/app server. lets call it hot deploy directory(HDD)) under webserver. Now web server specific class loader will come in to picture. It finds the new entry under HDD. Now, it finds if class has been already loaded by classloader in perm gen space, webserver will unload it from permgen space and load the new the one internally without server restart so that new changes(byte code) is reflected . As part of reload, webserver will also link the existing Epmloyee objects with new class definition in perm gen space so that new changes are reflected.

Is my understanding correct ?

Some links like this says Eclipse hot deployment is just automation of redeployment. what i believe it means is that eclipse automatically stop the server , republish and restart it without developer intervention. Buti i think its not true as this process is really quick as compared to start/publish/restart. Also if it would have been true, how session and other live objects will remain live after restart ? May be this link was true in past but not now as I find hot deployment works for classes in jar also

Chunchung answered 7/2, 2016 at 3:8 Comment(4)
Possible duplicate of What makes hot deployment a "hard problem"?Respire
@ivan its not duplicate . The link you mentioned is not about internal of hot deployment but about he challengesChunchung
The accepted answer to it does explain what's happening internally. Maybe you require even more details but that's another matter.Respire
fyi, there is no permgen in java8.Garmaise
P
10

Hot code deployment depends on the runtime capabilities. The answer you linked to does not mean that the automation stops the server deploys the new code and starts the server again. This would have been wasteful.

Instead, most of the Java application servers are able to redeploy the application. It means that the server would create a new web application class loader, load the new version of the application by this new class loader, in some cases it will migrate state (serialize/deserialize HTTP session), and drop the old version of the application.

Now the redeploy speed depends very much on the application itself -- how the application is initialized. Does it have to warmup caches? Does it have to satisfy the dependencies (a-las Spring, CDI)? Does it have to initialize Hibernate SessionFactory? Many factors are involved.

What Eclipse WTP naturally does is that it can trigger the redeployment process for the application container - that's it. A small application will not take long to redeploy, of course.

Unless there's a special runtime technology/container/framework and there is a special connector developed for Eclipse to take advantage of a hook that would trigger hot code updated for that specific technology. A good example is bndtools for OSGi runtime.

And just to remove some confusion:

Often people confuse HotSwap and hot deployment. The first one, HotSwap, is the ability of JVM to update class definition at runtime. The latter one, hot deployment, is the ability of application server to automatically deploy application, either incrementally or not, without restarting the JVM process.

So my answer is about hot deployment, and not about HotSwap. Hence I refer to hot deployment as an "automation" rather than a fundamental mechanism of the platform.

Perlaperle answered 7/2, 2016 at 17:19 Comment(3)
Thanks Antan. As you said Instead, most of the Java application servers are able to redeploy the application, but how Eclipse(ID) tells to server that it needs to redeploy the application. Does it place the new class files at specific location and server redeploys only those files or complete application ?Chunchung
Second point you said is ` in some cases it will migrate state (serialize/deserialize HTTP session), `,my question does it migrate the state of other objects like domain/service objects apart from session objects ?Chunchung
@emily Eclipse triggers full application redeploy. Regarding the state migration - it must be totally implementation specific. I haven't seen any other state being migrated besides HTTP session.Perlaperle

© 2022 - 2024 — McMap. All rights reserved.