First, Java overview
1. Four independent but related technologies in Java:
Java programming Language: Java source program
Java API: To connect Java library files, the official provide a lot of library files to improve the development of Java, through the API to connect to the appropriate library files.
Java class file format: The file format followed by the compiled Java program.
Jvm:java virtual machine: A generic virtual machine that runs across platforms.
The Java language, in conjunction with the Java API, writes out Java program code and then compiles it into a Java class file (Java bytecode, which is in Java class format) and then runs on the virtual machine.
2, the implementation of the JVM process:
1, one-time interpreter, interpretation of bytecode and execution, that is, each execution of the bytecode will be interpreted once.
2, the real-time compiler, that is, the byte code after the interpretation of the cache, run again, no longer explain. However, the cache requirements are too large.
3, adaptive compiler, only the use of high-frequency parts of the interpretation after the cache. In general, about 20% high-frequency use of the bytecode interpretation after the cache, the other one-time interpretation.
3. Types of JVM
(1) Hotspot JVM: Officially provided by Sun Company, contains the following two components:
The Jre:java run environment is +JVM, which is used to run Java. Includes JVM and Java core class libraries and support files. Jre=api+jvm
Jdk:java development Environment +JRE, which is used to develop Java, and can run, contains the JRE. Jdk=java Development Program +API+JVM (Minimal development environment for Java development)
After we developed our own Java program using the JDK (calling the Java API), we compiled our text Java files into Java bytecode using the compiler program in the JDK (JAVAC), running these Java bytecode on the JRE, the JVM parsing the bytecode, A system call that maps to a CPU instruction set or OS.
(2) Open source Jvm:openjdk
4. Types of Java:
JAVA SE: Standard Edition
JAVA EE: Enterprise Edition
JAVA ME: There are few applications for developing a JDK for handheld devices.
5. JAVA API
Java Official Class Library
Third-party class libraries
To implement a class library for a dynamic Web site:
Applet Class Library: The development of the applet is compiled first, and then embedded into the HTML, each client needs to install the applet plug-in to run. Similar to Microsoft's ActiveX. Unsafe, no longer used.
Servlet class Library: A CGI technique for Java. Enables Java to develop dynamic Web sites. Following the servlet specification, HTTP protocols and HTML documents can be identified. But static web pages also need to be generated in Java programs, resulting in late maintenance is difficult, and change the HTML code of a static page, also need to recompile.
JSP API: That is the elevation of the servlet. In an embedded way, Java code can be embedded into the HTML, so that the front-end HTML development and background Java development separate.
JSP Template: SSH
.jsp--> (Convert to servlet using Jasper) .java--> (convert. java to JVM with Javac) (. Class)
Ejb:java related to the implementation of many advanced features.
JMS: High EQ can be asynchronous message service.
JMX: Developing Java monitoring and management.
6. Running mechanism of Java web
(1) servlet Container:servlet container:
The Web server received a customer request--"discovery is a dynamic request to the CGI receiver via CGI sent to the servlet container (servlet container)-->web The container receives the CGI request, the Java source program (. java) Use the JDK compiler (JAVAC) to compile the library file into Java bytecode (. Class) and then send the bytecode to the JVM (virtual machine) to resolve the execution and then return the requested content.
The container can also monitor the changes of the source code in real time and recompile immediately after the change.
(2) Web Container:web container: Added the process of JSP conversion to servlet (. java) on a servlet basis
The Web server received a request from the client--"discovery is a dynamic request to the CGI receiver via CGI sent to the Web container (Web container)-->web container received a CGI request, the relevant source code (. JSP) into the servlet code (. java), which translates the JSP through (Jasper) into a servlet. --Compile the converted Java source program (. java) with the JDK compiler (. javac) with the library file into Java bytecode (. Class) and then send the bytecode to the JVM (virtual machine) to resolve and then return the requested content.
(3) Connector for Web container:
The Web container can contain a connector, skip the Web server, and directly face the user's request, this connector is tomcat.
That is, the user sends the request-to the Web container's connector-and starts the JSP into. Java-->java to. Class bytecode-->JVM parse and return the content after the client resolves.
Of course, you can also start by receiving customer requests via the Web server and then sending the JSP to tomcat-->. Java-->java turns into. Class bytecode-->JVM parse and return the content after the client resolves.
JVM instance: (multiple requests are not started with multiple JVM instances, only the JVM thread is started)
When multiple requests are in the Web container, multiple JVM threads are started.
7. Types of Web containers:
The kind of Web container (all Web programs that can run Java EE development):
WEBSPHERE:IBM Research and development, the share of more than 30%. Commercial-grade
WebLogic: Acquired by orcacle, accounting for 20% commercial-grade
Oc4j:oracle accounted for 10% commercial grade
Jboss:readhat, which is the encapsulation and development of Tomcat. Open source.
II. JDK
1. Installing the JDK
It is best to install Sun's JDK. To the official website to download. Not necessarily the newest package is the best. There are generally rpm and. Bin binary packages.
(1) installation package
(2) installation directory/USR/JDK
(3) Add the JDK binary directory to the environment variable path
(4) Set up the system service, let the JDK boot up.
2. JDK use
Third, Tomcat
1. Tomcat Basic Architecture:
The TWS demo version of the Web container developed by Sun, plus the ASF composite, Tomcat.
Tomcat is divided into multiple layers, namely:
Server: The ability to have a Web server that can directly receive requests from clients, or to receive CGI dynamic requests forwarded by Web servers such as Apache, each tomcat server is a Tomcat instance, When a tomcat real column is generated, one or more connectors are initialized to receive requests that are sent externally. A tomcat server typically opens only one tomcat engine. In server, multiple engines can be opened, and the server is associated with the engine called the connector, and the connector is divided into various, such as HTTPS,HTTP,PROXY,AJP and so on.
Service: Primarily as a connection between the server and the Tomcat engine, one or more connectors are associated to a Tomcat engine. There can be only one Tomcat engine inside a service. One and more connectors can be associated to the same Tomcat engine.
Tomcat Engine: Features a web container that performs requests that the server forwards through the connector.
Host: Implements the virtual host function inside the engine. By setting the default host for the Tomcat engine.
Context: The path alias, similar to the virtual directory in IIS, can be set in any directory outside the Web site virtual directory as the site directory to store Web site files.
When a tomcat server instance is generated, it initializes or registers one or more connectors (such as an HTTP request to generate an HTTP connector, HTTPS request generation HTTPS connector)--external request sends the request to the server connector-- The service associates the connector to the Tomcat engine on the-->tomcat engine processing request.
There can be multiple engines inside a server. A component called a connector (connector) that forwards a request to the engine for a server receipt. And the connector is divided into a variety of, such as HTTPS,HTTP,PROXY,AJP. Multiple requests forwarded to different connectors can be forwarded to the same engine. The service is to associate the connector to the engine.
。 But typically there is only one service inside a server, and only one engine inside a service.
2. Tomcat components:
Can be used in the engine, host,context various levels of components:
Realm: User authentication, in fact, is a user account database, these components can be used at the engine level, can also be used at the host level, can also be used at the context level. When used in the engine, the access engine requires authentication, such as when it is used in host, it requires authentication when accessing the virtual host.
Valve: Log access logs based on IP authentication.
Wrapper
3. Tomcat Installation
Installation package:
Source format, compiled with Java, generally not recommended with the source code.
. bin Binary Package
RPM installation Package
4. Detailed Installation Documents:
Server.xml: Describes the relationships between Tomcat components.
Web. xml: Default, Application Deployment descriptor
Deployment: Loading a class library that a Web application relies on into the JVM
/bin binary Directory
Catalina.bat is the main scripting program. Execute the other scripts as parameters.
/lib Library Directory
/webapps
5. Tomcat Configuration
6. Deployment:
Front end with Apache or Ngix as proxy, back end with Tomcat.
When using Apache at the front end, you can use the reverse proxy to communicate with multiple Tomcat via the AJP protocol to achieve load balancing.
Four, reverse proxy:
(a) The type of reverse proxy:
1, Apache several reverse proxy software:
Apache (three reverse proxy modules: MOD_PROXY,MOD_JK,MOD_JK2 requests Proxy to backend), and supports AJP and HTTP protocols with back-end communication-"Tomcat
Mod_proxy
Mod_jk
MOD_JK2: Is the new version of MOD_JK, but the application has a problem, has not been used, only with MOD_JK.
2. Reverse proxy and Tomcat communication protocol
AJP: Only Apache recognizes this communication protocol. Therefore, this protocol cannot be used in Ngix.
http
(ii) Configure the Mod_proxy agent:
1, install APR1.4 above version.
2, compile and install apache2.4 above version, need to load mod_proxy mod_http, MOD_MOD_PROXY_AJP, Proxy_balancer_module and other modules.
/usr/local/apache/bin/httpd-d dump_modules |grep Proxy//Use this command to see what modules are installed.
3. Configure the Apache global configuration segment or the virtual configuration segment to add some content to implement the AJP or HTTP protocol to connect back-end tomcat.
(iii) configuring JK Agent:
1, install APR1.4 above version.
2, compile and install apache2.4 above version, need to load mod_proxy mod_http, MOD_MOD_PROXY_AJP, Proxy_balancer_module and other modules.
3. Install JK Software on Apache Web server side. Software called Tomcat-connectors
4. Configure Apache to load related modules in Apache.
Wu, Deltamanager
This article is from the "Network Line World" blog, please make sure to keep this source http://kuangkuang.blog.51cto.com/838/1695089
Three--tomcat of---of Linux Web Chapter