Write advanced applications 2

zhaozj2021-02-08  455

New synchronization

Before Java 2 is released, synchronized methods and objects always trigger some extra performance interference because the mechanism used to implement this code lock has adopted a global monitor registration, which is just a single thread in some areas. (Such as search for existing supervisors). In the newly released Java 2, each thread has a surveillance registration, eliminating many existing performance bottlenecks.

If you have used other locking mechanisms to avoid performance interference of synchronous methods, it is now necessary to reinvitably visit these code and consider new Java 2 new lock technology.

In the example of creating a monitor in the following, you can increase the speed by 40%. The time used in JDK1.1.7 and the Java 2 using Sun Ultra 1, 14 ms and 10ms, respectively.

Class mylock {

Static integer count = new integer (5);

INT test = 0;

Public void letslock () {

SYNCHRONIZED (count) {

Test ;

}

}

}

Public class locktest {

Public static void main (string args []) {

MYLOCK ML = New mylock ();

Long Time = system.currenttimemillis ();

For (int i = 0; i <5000; i ) {

ml.letslock ();

}

System.out.println ("Time Taken ="

System.currentTimeMillis () - TIME));

}

}

Java Hotspot

Java Hotspottm Virtual Machine is a next-generation virtual machine for Sun Microsystem. Although the specification used by the Java HotSpot virtual machine is the same as the specification used by the Java 2 virtual machine, it has been redesigned, and the most advanced technology can be used, so that in the next few years, it can provide a powerful and powerful. Reliable performance engine. Java HotSpot virtual machines are available:

You can detect and accelerate real-time dynamic optimization techniques for performance critical code.

Super fast threads designed for the maximum performance of threads.

Accurate and reliable garbage collectors that can be quickly obtained.

Due to its simple, high-level, and object-oriented design, it is important in maintainability and scalability.

Just-in-Time compiler

The simplest tool used to improve application performance is the Just-In-Time (JIT) real-time compiler. JIT is a code generator that converts Java bytecode to a local machine code. The Java program called by JIT, which is often much higher than the speed of performing a word code by the interpreter.

The JIT compiler is first in the Java Development Kit (JDKTM) 1.1.6 as a performance update, and now it is a standard tool that you call when you use the Java Interpreter command on the Java 2 platform. You can use the Java virtual machine's -djava.compiler = none option to make the JIT compiler to expire, which is described in more detail at the end of JIT.

转载请注明原文地址:https://www.9cbs.com/read-892.html

New Post(0)