Reloading Java Applications Like A Pro

Reloading Java Applications Like A Pro

1bc80e2eee2adeaa8bb577798d92e9d0?s=128

Anton Arhipov

March 14, 2013
Tweet

Transcript

  1. reloading java applications like a pro Anton  Arhipov  

  2. whoami anton arhipov @antonarhipov jrebel product lead zeroturnaround

  3. agenda • the time sink • application updates (with jrebel)

  4. make a change build, deploy, wait check the change the

    turnaround
  5. package everything into WAR/EAR rackage modules into JARs compile classes

    copy static resources resolve dependencies build
  6. exploded directory deployment

  7. public class Launcher { public static void main(String[] args) {

    Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(8080); server.addConnector(connector); WebAppContext context = new WebAppContext("war", "/"); server.setHandler(context); server.start(); } } jetty launcher
  8. “…I  know  about  JRebel,  but  I  cannot   pay  for

     it,  so  I  tried  Maven…”                                                                                        -­‐  Stackoverflow  
  9. getResource(“hello.html”)   read(“src/main/.../hello.html”)  

  10. package everything into WAR/EAR rackage modules into JARs compile classes

    copy static resources resolve dependencies build
  11. package everything into WAR/EAR rackage modules into JARs compile classes

    copy static resources resolve dependencies build
  12. no build! • compile with your IDE • prefer exploded deployment • avoid

    <<mvn clean install>>
  13. 1–60s 30s$–$15min ~1min container boot time application deployment navigation redeploy’s

    time
  14. h@p://dow.ngra.de/2010/12/14/jee-­‐oss-­‐container-­‐startup-­‐Jmes-­‐apples-­‐vs-­‐oranges/   container startup time

  15. h@p://zeroturnaround.com/java-­‐ee-­‐producJvity-­‐report-­‐2011/  

  16. Externalized   Temporary   Serializable   DerivaJve   State  

    why code reloading is hard?
  17. MyObject   MyObject.class   OldClassLoader   NewClassLoader   MyObject.class  

    MyObject   Recreate  object   naiive class reloading
  18. Classes Libraries OldClassLoader NewClassLoader Sevlet New Classes New Libraries Sevlet

    Session Session init()   App State App State serialize/deserialize
  19. Classes OldClassLoader NewClassLoader Sevlet New Classes New Libraries Sevlet Session

    Session App State App State
  20. MyObject MyObject.class   OldClassLoader Code   101000101   100010010  

    Debugger HotSwap   New  code   111000100   101010010   New  code   111000100   101010010   hotswap Make  changes  
  21. MyObject MyObject.class   OldClassLoader Code   101000101   100010010  

    New  code   111000100   101010010   JRebel   Framework   ConfiguraJon   (XML,  annotaJons,..)   jrebel Make  changes  
  22. HotSwap   JRebel   Changing  method  bodies   +  

    +   Adding/removing  methods   -­‐   +   Adding/removing  constructors   -­‐   +   Adding/removing  fields   -­‐   +   Adding/removing  classes   -­‐   +   Adding/removing  annotaJons   -­‐   +   Replacing  superclass   -­‐   -­‐   Adding/removing  implemented   interfaces   -­‐   -­‐   jrebel vs hotswap
  23. in action

  24. Java App Framework Conf XML HTTP request

  25. Java App Framework Conf XML HTTP request 1) Stop request

  26. Java App Framework Conf XML HTTP request 2) Check resources

  27. Java App Framework Conf XML HTTP request 3) Reconfigure the

    framework
  28. Java App Framework Conf XML HTTP request 4) Resume request

  29. Java App Framework Conf XML HTTP request PROFIT! J

  30. Java App Framework Conf XML HTTP request OpJonally:   File

     system     PUSH  
  31. None
  32. application reloading is hard • requires more than just class reloading

    • reloading of different components should appear in particular order • bootstrapping
  33. with java ee

  34. jrebel for java ee • JSP • JAX-RS • JAX-WS • JSF • CDI • JPA

    • EJB • Jasper • Jersey, CXF • Metro • Mojarra, MyFaces • Weld • EclipseLink, OpenJPA, Hibernate
  35. goes cloud

  36. Remote Deployments • Development servers • Virtualized environments • Cloud environments

  37. Remote Deployments 0. make a change 1. git commit; git

    push 2. mvn clean install 3. deploy.sh
  38. 0. make a change 1. compile 2. synch & reload

  39. h@p://bit.ly/33degree2013     win a free license

  40. Questions? @antonarhipov anton@zeroturnaround.com