Accelerate Java application development speed 2-accelerate project debugging startup speed and java application development

Source: Internet
Author: User
Tags grails

Accelerate Java application development speed 2-accelerate project debugging startup speed and java application development

In the previous article on improving the speed of Spring/Hibernate, we mainly used some techniques to increase the startup speed, or we could not do hot deployment or hot replacement of the class. Therefore, write another article on hot deployment/hot replacement. Many people have introduced this knowledge before, but it is scattered. The purpose of this article is to aggregate them. This article takes the HotSpot virtual machine as an example.

First, let's look at two concepts: Hot deployment and hot replacement.

Hot deployment

That is, when the container is running, reload the class or reload the entire project. A common solution is to use a custom ClassLoader;

Partial loading examples: JSP and Play frameworks;

Example of reloading the entire project: for example, Tomcat and Jetty. By default, the system regularly checks whether the class file has been modified. If so, uninstall the current container and reload the entire project ). The disadvantage of this situation is obvious: You can only reload the entire class/project, not just replace the part of the class.

Introduction to JSP hot deployment:

Http://www.linuxidc.com/Linux/2013-05/83816.htm

Introduction to Tomcat hot deployment:

Http://www.94it.cn/a/jingxuanboke/2013/0501/4578.html

Play! Framework:

Http://mingj.iteye.com/blog/307238

 Hot replacement

The advantage of hot replacement over the previous hot deployment is that it can replace partial replacement within the class, such as the method body, addition, deletion method, and field, rather than the entire class. Common Implementation Methods: HotSwap, HotSwap patch,

  HotSwap

You can only hot Replace the method body. You only need to enable the debug mode in eclipse, idea, and other development tools.

  HotSwap patch DCEVM

This patch enhances HotSwap and can add or delete class fields, methods, and change the class parent class. It must also be debugged in debug mode. For more information, see the following document.

Hotswap User Manual

DCE Problems and Solutions

I used jdk1.6.0 _ 25 for testing. No problem is found. jdk1.6.0 _ 26 is not supported, and I did not succeed in testing jdk7_13 and jdk7_21. Official website said it is based on JDK7-b102 compiled. I guess these two versions are incorrect.

 Java agent + Instrumentation

1. Spring-Loaded

SpringSource is released on the official website. It is used in Grails 2 and allows: Add/modify/delete methods, fields, and constructors. Annotations on the Type/method/field/constructor can also be modified, and values of the enum type can also be added/deleted/modified.

Usage:

Java code
  1. -Javaagent: <pathTo>/springloaded-{VERSION}. jar-noverify

For example, you can specify the above configuration in the VM parameter when executing tomcat/jetty. It does not need to be executed in debug mode. If idea is used, press Ctrl + Shift + F9 to compile the current class/Ctrl + F9 to compile all the changed classes.

 2. Fakereplace

Similar to Spring-Loaded, refer to its official website for details:

Https://github.com/fakereplace/fakereplace

Https://github.com/fakereplace/fakereplace/wiki/How-It-Works

It supports some frameworks:

  • Seam 2
  • Weld (basic integration)
  • JSF
  • Metawidget
  • Hibernate (if the entity is modified, restart the entire EMF. It is not very fast)
  • Resteasy

The specific usage is also specified in the VM parameter:

Java code
  1. -Javaagent:/path/to/fakereplace. jar

You can download the jar package at the following address or compile it yourself.

Http://repo.grails.org/grails/plugins-releases/org/fakereplace/fakereplace-dist/1.0.0.Alpha2/

 

It provides some configurations, such:

Java code
  1. -Javaagent:/path/to/fakereplace. jar = packages = com. mycompany. myclasses, log = trace
  • Packages that require hot replacement
  • Log (optional) supports trace, debug, info, and error.
  • Index-file fakereplace index path. Fakereplace stores this file after the first run to accelerate startup
  • Dump-dir when hot replacement, the Dump class to this directory, only useful when developing Fakereplace
  • Port Fakereplace listening port

The two implementations are very similar. Spring-Loaded uses CGLIB to implement proxy, and FakeReplace uses Javassist for implementation.

There is also Agent Smith, but N has not been maintained for a long time. In fact, the Play framework also uses Instrumentation, but it is the whole replacement, so it is not classified.

All of the above have disadvantages: for example, when I write a spring Project, I cannot dynamically load the configuration such as @ RequestMapping or the configuration file. These are supported in powerful JRebel.

JRebel

JRebel is my simplest and most powerful hot replacement/hot deployment tool. However, the disadvantage is that it is charged and not cheap. All the information we introduced earlier is free of charge. First, let's take a look at the comparison between the features it supports and JVM Hot Swap:

JavaEE support JRebel JVM Hot Swap
Loading time <1 s <1 s
Memory leakage None None
Change the class structure
Change Method body  

 
 


Add/delete Methods    
Add/delete Constructor    
Add/delete Fields    
Add/delete classes    
Add/delete Annotation    
Change static field value    
Add/delete enum Value    
Change Interface    
Replace parent class    
Added/deleted Interfaces    
Instant build
Skip building the WAR directory    
Skip the. WAR/. EAR class update build    
Skip. WAR/. EAR resource update build    
Map multiple source directories to A. WAR/. EAR target directory.    
Use the include/exclude mode to map classes and resources
Map multiple sourcde Directories In Ant style Mode
Use System Properties to make the ing Machine irrelevant
Maven plugin
Remote/cloud
Update applications over HTTP

 

JavaEE support

Jsp el changes
JSP Scriptlet changes
EJB 1.x session bean interface changes
EJB 2.x session bean interface changes
EJB 3.x session bean interface changes
EJB 3.x: adding new EJB
EJB 3.x: adding new EJB reference
JSF changes (Mojarra)
Bean Validation support (Hibernate Validator)
JAXB annotation changes
JAX-RS chang es (RESTEasy, Jersey, CXF)
JAX-WS support (Metro, CXF)
JPA changes (Hibernate, EclipseLink, TopLink, OpenJPA)

CDI changes (Weld)

 

Framework Support
Spring Framework 2.x or later
Hibernate
JBoss Seam 2.x or later
Google Guice
Struts 1.x, 2.x
Wicket
Stripes 1.5 or later
View the complete list of supported frameworks

 

Proxy Support

CgLib
Javassist

 

OSGi support

Apache Felix
Eclipse Equinox

 

From the list above, we can see that it is not generally powerful.

Next let's take a look at how to use IT (using IDEA as an example ):

1. Click Run as shown in, and then click Edit Configuration...


 

2. In the pop-up window, enter the jrebel. jar location as shown in.


Similar to the previous Java Agent configuration.

3. After the class is started, press Ctrl + F9 to re-compile the class. Then execute the program to see the changes.

4. Eclipse embedded tomcat configuration:


 

 

It is very simple to use. Note: If you use web containers such as tomcat and jetty, disable their reload, such as jetty. You can configure

<ScanIntervalSeconds> 0 </scanIntervalSeconds> or <reload> manual </reload>.

JRebel also provides plug-ins such as Eclipse, IDEA, and Maven. In fact, there is no need to add plug-ins. It is very easy to directly configure Java agent. You can also configure

If you want to enable or disable support for some frameworks or JavaEE, you can enable or disable VM parameters as follows:

-Drebel. spring_plugin = true
-Drebel. aspectj_plugin = true
-Drebel. struts2_plugin = true
-Drebel. hibernate_plugin = true
-Drebel. jackson_plugin = true
-Drebel. log4j-plugin = true

Complete Framework Support List

You can also configure a rebel. xml file for selective construction:

Http://zeroturnaround.com/software/jrebel/how-to-configure-rebel-xml/

For more configurations, see its official JRebel manual.

This article describes all of the hot deployment/hot replacement implementation methods I have seen. Please add some suggestions.

Reference resources:

Hotswap User Manual

DCE Problems and Solutions

Dynamic Code Evolution VM

Official Spring Loaded website

Official FakeReplace website

Javasc401: HotSwap and JRebel-the story behind the scenes

Integrate JRebel with Maven

Integrate JRebel with Eclipse

Integrate JRebel with IDEA

JRebel Manual


Java programming is known to accelerate to 10 meters per second acceleration is 2, 20 seconds after the speed of 20 seconds walk through and average speed

Public class Test {

Public static void main (String [] args ){

Double v0 = 10; // initial speed
Double a = 2; // Acceleration
Double t = 20; // time

// V = v0 +
Double v = v0 + a * t;

// S = v0 * 5 + 1/2 * a * t
Double s = v0 * t + (1/2) * a * Math. pow (t, 2 );

System. out. println ("After 20 seconds, speed is:" + v );
System. out. println ("After 20 seconds, shift is:" + s );

}

}

How to speed up startup!

1. If you do not have a USB device, disable all USB devices in Device Manager-Universal Serial Bus Controller.

2. Open the "hardware" tab in "System Properties", open "Device Manager", expand "ide ata/ATAPI controller", and double-click to open the "secondary IDE channel" property, click the "Advanced Settings" tab and change the transmission modes of devices 1 and 2 to DMA. If available, select "NONE" for the device type, and click "OK" to complete the settings, set "Main IDE channel" in the same way ".

3. Remove unnecessary programs from the System Configuration Utility and registry. (This can be done by the optimization software)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.