0

I find classreloading would be tremendous increment in productivity. I think redefining class is very limited.

Over the years we found several workarounds to keep constantly changing part of our applications in some kind of domain specific language(DSL) or in more free form like in XML or json or properties files or are using scripting language like javascript where redefining function (){} from string is possible and overwriting previous function definition is easily possible.

My thoughts:

Annotations can be there to make a class reloadable, or make a class act as script i.e. a .java file can be treated as a DSL.

@Reloadable 
public SomeReloadableClass{

}

@Script 
public SomeReloadableClass{

}

Now there will be concerns that reloadable classes's references might be help elsewhere which cause memory leaks while trying to unload a class.

To overcome this there should be some constraints enforced. Although this part is hard but we can have either interface contracts, or through annotations. If required there can be a contract imposed for exports and dependencies much like OSGi descriptors but within a class using interceptors or interfaces. It should be simpler than OSGi because OSGi cares for versions dependency matching etc which are not required on a per class basis.

@Reloadable (exports='..., ...')
public SomeReloadableClass{
    public start(){ ...}
    public stop() { ...}
}

I feel this feature would be extremely handy, as a byproduct we can use java as configuration files, java as DSL while most parts of the program will still be a compiled monolith to be adequately performant.

A javascript program always uses javascript or json as configuration descriptor, which is again a javascript object notation. We should be able to do the same in java or in any jvm language.

Is java module system focusing on this?

Note: I feel this is not quite in a question format, rather a proposal, and in that sense its in the wrong Q-A site. I am not sure where to move, so I am thinking aloud here. Suggest where to move it.

samarjit samanta
  • 1,285
  • 2
  • 16
  • 29
  • I'm not clear on the difference between "class reloading" and hot code replace. – chrylis -cautiouslyoptimistic- Oct 14 '15 at 20:23
  • I feel the use case of reloadable classes isn't quite fleshed out. Why won't a per-class class loader work in your case? Why even have the need to reload classes? – Tassos Bassoukos Oct 14 '15 at 21:05
  • @chrylis - hot code replace is called redefining class, but that is limited to only redefining of methods but not changing class structure like creating new methods. I am not sure if changing method signature is even supported. But either way its not meant to be used in production as its brittle. – samarjit samanta Oct 15 '15 at 03:20
  • @Tassos Bassoukos - use case is a more modular approach where I can upgrade part of an application. Have configurations written in java files instead of properties or other free forms. During development also it will be a huge productivity gain not having to restart servers. Everything will be much like OSGi but without the extra pain of creating bundles for every class. – samarjit samanta Oct 15 '15 at 03:29
  • @samarjitsamanta if time needed for restarting app servers is your blocker, you're doing something wrong. But then again, feel free to reimplement a dynamic langauge on top of Java. – Tassos Bassoukos Oct 15 '15 at 10:22

0 Answers0