I want to fly higher
programming Explorer
posts - 114,comments - 263,trackbacks - 0
1.Spring-loaded项目核心作者Andy Clement
     github主页:
        https://github.com/aclement
    可以看到是一个开源大神.

2.往来邮件,其中有很多东西值得学习:尤其是红色部分

2015年6月26日

Hi,

Really all the docs is what I wrote in that bug report: https://github.com/spring-projects/spring-loaded/issues/70

Yes you need javaagent (and noverify), the -Dspringloaded=watchJars=foo.jar:bar.jar part is just the options that get passed to the agent to configure the behavior.

There are a couple of regression tests in the class: SpringLoadedTestsInSeparateJVM

Remember that you only need the short part of the jar name (foo.jar), I’m not sure what will happen if you fully qualify the path to the jar.

You could turn on -Dspringloaded=verbose to check spring loaded is basically functioning (can’t recall if I added extra verbose output specifically for jar reloading).

cheers,
Andy

On Jun 232015, at 5:09 AM, landon <340706410@qq.com> wrote:

Hi,
   I'm a software engineer in china.I'm interested in spring-loaded recently.But pre 1.2.3,it's only reload calsses.In github,i saw you said 1.2.4 can do reload class files in jar.
  eg,with -Dspringloaded=watchJars parameters.
  My question is:
  1.Can you give a detail examples,it's also need -javaagent?
  2.I build a jar using the master code in github,but i test it's no effect to reload jar files.I want to know when the 1.2.4 version can support the function.
   _____________________
   Thanks very much.
   Best Regards.


2015年6月29日

Hi,

Possibly it could be a windows thing I suppose. This works perfectly for me:

Code.java
===
public class Code {
  public static void main(String []argv) {
    while (true) {
      new Bar().run();
      try { Thread.sleep(2000); } catch (Exception e) {}
    }
  }
}
===

Bar.java
===
public class Bar {
  public void run() {
    System.out.println(“one");
  }
}
===

javac *.java
jar -cvMf spring-load-example-main.jar Code.class
jar -cvMf spring-load-example-extra.jar Bar.class

java -classpath spring-load-example-main.jar:spring-load-example-extra.jar -Dspringloaded="verbose;watchJars=spring-load-example-extra.jar" -javaagent:/Users/aclement/gits/spring-loaded/springloaded/build/libs/springloaded-1.2.4.BUILD-SNAPSHOT.jar -noverify Code

This will print ‘one’ every second.

Then I change Bar, edit the ‘one’ and replace with ‘two’. Then:

javac Bar.java
jar -cvMf newjar.jar Bar.class
mv newjar.jar spring-load-example-extra.jar

This triggers some trace output and then it starts printing two:


INFO: Observed last modification time change for /Users/aclement/gits/spring-loaded/springloaded/build/libs/play/spring-load-example-extra.jar (lastScanTime=1435594228140)
Jun 292015 9:10:29 AM org.springsource.loaded.agent.Watcher determineChangesSince
INFO: Firing file changed event /Users/aclement/gits/spring-loaded/springloaded/build/libs/play/spring-load-example-extra.jar

Reloading: Loading new version of Bar [PH0x0kq]

two
two
two


This is on a mac. Can you look at the timestamps of your files inside the jar? Confirm it is changing to something more recent inside the jar? That is what is being used to determine if an update occurred.

> can the spring-loaded used to the production environment?

Nothing prevents it but it does add significant overhead to running code because it introduces a lot of indirection to make the reloading work.

cheers,
Andy

On Jun 282015, at 7:29 PM, landon <340706410@qq.com> wrote:

Hi,
  I'm so excited to receive your reply.Thanks very much.
  I say my example:
     I have two jars,spring-load-example-main.jar,spring-load-example-extra.jar,The former depends on the latter.The classes in spring-loaded-example-extra.jar often changes,so i want to reload the jar using spring-loaded.
      My Launch script is:
                 @echo off
                 cd /%~dp0
                 java -Dspringloaded=verbose;explain;watchJars=spring-load-example-extra.jar -javaagent:springloaded-1.2.4.BUILD-SNAPSHOT.jar -noverify -cp spring-load-example-main.jar;spring-load-example-extra.jar com.mavsplus.example.springloaded.SpringLoadedExample
     The spring-load-example-main.jar,spring-load-example-extra.jar,springloaded-1.2.4.BUILD-SNAPSHOT.jar are in the same directory.When i want to reload the spring-load-example-extra.jar,i repackage the jar and replace to the directory and override it,but it has no effect.That's all.I also used jrebel,it can reload ja,but must assign the monitor reload jar classes dirctory,i also cannot to ovverride the reload jar to reache the reload goal.
 And Finally i want to ask: can the spring-loaded used to the production environment?


2015年6月30日

Hi,

Sorry about that - I made the change you noticed to correctly use File.separator and committed that (thanks for telling me about it). I notice a TODO had been left there saying to sort it out for windows!

   ->I ask another question,i know if used to production environment,it maybe has some performance loss.To avoid it,i suggest,when we decide to reload the jar,we can send a message to notice to reload,and to avoid must be monitor the jar change every seconds.
    ->can extract a mini-framework only to reload jars.
    ->or can add a switch,by the switch,we can reload jars manually?
      if above can reduce the performance loss?

It isn’t the act of watching the jar that is expensive or the act of loading the jar changes into the system. Basically for code to support reloading it goes through a massive transformation process at loadtime, this transformed byte code is slower, but it needs to be done up front just in case you reload anything.  To minimize the performance impact you would reduce what is made reloadable - so in the jar watching case watch as few jars as possible. Maybe break big jars into smaller ones so you can watch only a subset of the jars.

cheers,
Andy

On Jun 302015, at 3:00 AM, landon <340706410@qq.com> wrote:

Hi,
  First,Thanks very much to reply me.
  Okay,I Got the reason,you are right,it's the os environment problem.I Browse the source code,i find the code,{@link org.springsource.loaded.TypeRegistry#private boolean couldBeReloadable(String slashedName)},The method 689L:
       int lastSlashPos = slashedName.lastIndexOf('/');
   The Seperator is unix seperator,not windows.I change it to the cross-platform code:
       int lastSlashPos = slashedName.lastIndexOf(File.separator);
    And finally,I rebuild the source code and got the new jar.I tested,it can reload jars perfectly!

   ->I ask another question,i know if used to production environment,it maybe has some performance loss.To avoid it,i suggest,when we decide to reload the jar,we can send a message to notice to reload,and to avoid must be monitor the jar change every seconds.
    ->can extract a mini-framework only to reload jars.
    ->or can add a switch,by the switch,we can reload jars manually?
      if above can reduce the performance loss?



2015-7-2

Hey,
Actually email is probably the best way to communicate on this, I don’t work on spring loaded all that much, only occasionally.
           ->two jars,main.jar and patch.jar,when launch main,i used a classloader load classes in patch.jar and put them to a Map,and some logic used the class intance...when some logic changes,i send a message(eg.use http) to the main process(it's a network program,can listen),when receive the message,i used another classloader to load the new patch.jar and re-fill the Map.By this method,i can implement some hot-swap logics,new request can used the new classes from Map...
I think there are use cases where that can work fine and you don’t need the full flexibility of a general purpose reloading system like spring loaded. You just have to make sure those instances don’t leak into other places where you can’t keep track of them as you’ll want to get rid of all of them when loading a new version.
     ->another question is:i think the hot-loaded has a deadly problem is : the Data in the class instance or in the memory...when reload the new class,the data in the old class instance was lost...
 to avoid it,in the class implemention,only have method/logic,not has property/data...put all data to a common place...but in my opinion,in oop,data and actions in fact ,they are together...so this is the confict.
         ->so can you give me some suggestion or give me a good practice?
With spring loaded the class instances remain around, they change on the fly to support new fields and methods are not rebuilt. This can cause issues because constructors are not re-run for pre-existing instances and so new fields added to existing objects may not be set. I think, in your case, you can break encapsulation by keeping state separation to behaviour if it is necessary and helpful for your use case - don’t be forced to keep them together if it makes your system less flexible than you need. I don’t see why you can’t have a bean that keeps state and then a class something like XXXOperator that operates on those state objects.  Or perhaps you could have a constructor on your objects that takes in one of the older objects and copies the state into the new instance before you discard the older object.
cheers,
Andy

On Jul 1, 2015, at 6:47 AM, landon <340706410@qq.com> wrote:

Hi,
  So excited to reply me.Thank you.
  Here, i have two questions want to interchange with you.
      ->I write a function used to reload jar.The implementation is:
            ->two jars,main.jar and patch.jar,when launch main,i used a classloader load classes in patch.jar and put them to a Map,and some logic used the class intance...when some logic changes,i send a message(eg.use http) to the main process(it's a network program,can listen),when receive the message,i used another classloader to load the new patch.jar and re-fill the Map.By this method,i can implement some hot-swap logics,new request can used the new classes from Map...
           ->how would you evaluate my way?
     ->another question is:i think the hot-loaded has a deadly problem is : the Data in the class instance or in the memory...when reload the new class,the data in the old class instance was lost...
 to avoid it,in the class implemention,only have method/logic,not has property/data...put all data to a common place...but in my opinion,in oop,data and actions in fact ,they are together...so this is the confict.
         ->so can you give me some suggestion or give me a good practice?
     ->finally,can you give a contact way the except email.i think it's low efficiency.
  Cherrs.



3.感受
    1.开源的力量真是伟大!
    2.开源大神的回复真是给力!
    3.我也会加入开源的大军中!
posted on 2015-07-01 21:06 landon 阅读(6683) 评论(3)  编辑  收藏 所属分类: JVMHotSwap

FeedBack:
# re: Spring-Loaded 使用Ⅲ -与其作者Andy Clement往来邮件
2015-07-29 13:57 | David1228
Good!!!  回复  更多评论
  
# re: Spring-Loaded 使用Ⅲ -与其作者Andy Clement往来邮件[未登录]
2015-09-23 13:22 | zy
博主你好:

我按照你的博客测试,watchJars并没有起作用啊,是我的版本问题吗?我从github上下的springloaded-1.2.4.RELEASE.jar ,和你所使用的springloaded-1.2.4.BUILD-SNAPSHOT.jar会有区别吗?
我的测试代码是借用的你与大神邮件中的测试代码。  回复  更多评论
  
# re: Spring-Loaded 使用Ⅲ -与其作者Andy Clement往来邮件
2015-10-05 23:04 | landon
@zy
http://www.blogjava.net/landon/archive/2015/10/05/425994.html#427599
_______
看一下这下面我的评论回复.  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: