Web request Process
- How to initiate a request: browser,httpclient
- HTTP parsing: chrome, Cache
- DNS domain name resolution: domain cache
- Cdn: load, Dynamic acceleration, back to source
Java I/O
- Basic architecture of the i/0 class library: byte manipulation, character manipulation, conversion of byte characters
- Disk i/o: kernel space, user space, synchronous, asynchronous, memory-mapped
- Network I/O working mechanism: TCP state transformation, Network transmission factors, Socket Working mechanism, communication link, Data transmission
- How NiO works: BIO CPU is preempted, channel,select,selectionkey,bytebuffer, data distribution
- I/O optimization: disk I/O optimization: raid,
- TCP Network Parameters: timeout, Port range, Network i/o: reduced number of interactions, reduced network transfer size, encoding, synchronous/asynchronous, blocking/non-blocking.
Design Mode: Adapter Mode (from One interface state to another), adorner mode (functions that extend the existing Interface)
Java Coding Issues
-
Common encodings: ASCII (+), iso-8859-1 (gb2312,gbk,gb18030,utf-16,utf-8),
-
Encoding and decoding
The encoding involved in the Web:
- URL encoding: URL encoding and QueryString encoding separate, set Connector encoding urlencoding= "UTF-8" usebodyencodingforuri= "true".
- Http header encoding: can not transfer the fee ASCII characters, if need to transfer, first with Urlencoder encoding, the server and then decode
- Post Form: the encoding is set by contenttype, the server is set with filter request.setcharacterencoding decoding, The upload is the byte stream does not encode.
-
JS encoding: js file encoding is inconsistent with HTML encoding, so the default setting is Charset. Encodeurlcomponent two-time encoding and decoding
-
Multi-Language Support: Nginx adds a multi-language Conversion.
Javac Compilation principle
- Lexical analysis, Grammar analysis, symbolic table construction, annotation processing, Labeling and grammar checking, data flow analysis, type conversion, byte code
- Implementation Class: com.sun.tools.javac.parser.Scanner, Parser
- Visitor pattern: decoupling stable data structures from the variable data structure
In-depth class file structure
- JVM Instruction Set
- class file Header
- Constant pool
- Class information
- Field and methods
- Class properties
- Javap
In-depth ClassLoader work mechanism
- Classloader:class loaded into jvm, class by who loaded, loaded into JVM uniform object Format
- Classloader:findclass,defineclass,resolveclass
- Type: Bootstrap Classloader,extclassloader,appclassloader
- Custom class, Hot deployment of classes:
- Dynamic loading of java: jsp dynamic loading
JVM architecture and how it works
-
JVM architecture:
By simulating a computer to achieve the functions of a computer: instruction set, compute unit, addressing, register, storage.
Class loading, execution engine (interpretation execution, JIT local execution, register Execution) different JVM implementations, Memory area, Local method call
-
JVM Working mechanism
stack-based working mechanism: platform-independent, compact, and reduce data volume
JVM Memory Management
-
Physical memory vs. Virtual Memory: virtual memory and physical memory N:1 when a virtual memory is inactive, the mapped physical memory is moved to the disk file (the paging file).
-
Kernel Space and user space,
-
Java Memory components: heap, thread, class and class load, Nio,jni
-
JVM memory structure: register, heap, stack, method area, constant Pool
-
JVM memory allocation: static allocation, heap allocation, stack allocation
-
JVM Memory Reclamation: Objects unreachable by the root object can be recycled (garbage detection), generational garbage collection Y,s1,s2,old,perm
Serial Collector,parallel Collector,cms Collector
CMS for old and Perm zones, minor GC with multithreading
DISABLEEXPLICITGC,SYSTEM.GC (). turned into air conditioning, did not release nio, need to change to explicitgcinvokesconcurrent
Direct Memory Analysis Tool SJDRECTMEM
How Servlets work
-
Servlet container: Tomcat's Startup class XX.startup.Tomcat, a Web application corresponding to a standardcontext container, the added listener inherits the Lifecyclelistener interface
globalwebxml>webfragement.xml>web.xml; Servlets are packaged into Standardwrapper
-
Servlet instances: Defaultservlet and Jspservlet
-
Servlet architecture: Use the façade design pattern to get the Data.
-
How Servlets work: by XX.http.mapper find the corresponding wrapper container, you must execute the filter chain
-
Listener:servletcontextlistener in the servlet can no longer add new, spring Contextloadlistener implements the listener, initializes the spring container
-
How filter works: multiple filter strings into one filterchain,url match: exact match, road strength match, suffix match
Session and Cookie
Session and Cookie are designed to keep the user interacting with the backend server, and the number and size of cookies are limited
-
Understand Cookies: no more than 50, size not more than 4095
-
To understand that the Session:standardsession object is persisted into session.ser, you must call the Sevlet container's stop method, request.getsession () to create
-
Cookie security and Compression: cookie modifiable (expiration time, encryption, unique key,httponly with browser or IP features), security implications, can be compressed with gzip and deflate to break storage limits and reduce bandwidth
-
Distributed session Framework: application of writable session items and cookie items Unified management, Session distributed cache storage, Inputhttpsession
Jump application, SessionID in all domain names are written to the cookie, in addition to the User's private information to generate a unique key (such as request ip, certificate files, Browser information).
-
Form repeat commit: each request is with a token, check the token and the session is consistent, after the request disable button
-
Multi-session Unified: Cookie and session to unify, take a unified session, QR code Scan code login: PC timed pull the QR code login there is no login, mobile phone sweep, send two-dimensional code information, the User's sessionid, sent to the service, the mark verification through, Send the SessionID to the end, the only Information.
Tomcat's system architecture and design patterns
-
Tomcat's Overall Design:
Connector and Container,container correspond to multiple service, One service can set multiple connector
The connector is responsible for encapsulating the request data and the return data into request and response, which is handled by Container.
The default connector in TOMCAT5 is Coyote.
Container is a chain of responsibility model that contains engine>host>context>wrapper, which can define periodic events in backgroudprocess,
Other Components: security,logger,session,mbeans,naming
-
Façade mode
You can't expose your data too much, limit it through a façade, HttpRequest and Httprequestfacade
-
Observer pattern
Made up of subject,concretesubject,observer,
Lifecycleevent defining themes, Lifecyclesupport managing the relationship between event and Observer
-
Command mode
Separate the responsibility for the issue of the order and the responsibility for the execution of the order Command,invoker,receiver composition, Httpprocessor and Containerbase
-
Responsibility chain Model
The responsibility chain pattern is a chain of many objects and objects ' home references, such as pipeline and valve in Tomcat.
Analysis of the working principle of jetty
-
Jetty Basic architecture: All extension components are added as handler to the server, with Handlerwrapper and handlercollection components
-
Jetty Startup Process: Handler has a parent-child relationship, initiates an mbean registered on jmx, and finally starts connector
-
Accept request: based on HTTP request: CONNECTORENDPOINT,AJP request: based on ajp13parser, nio processing: monitoring and processing separate
-
Processing Request: Servletholder is a servlet's adornment class, added to handler
-
Integration with jboss: ajp-based integration
-
Comparison with tomcat: short life cycle connection using tomcat, long connection with jetty
The Spring framework design concept
-
Spring Skeleton architecture: The core of Bean,core,context,core is the helper class that discovers, establishes and maintains relationships between beans, and the context is the ultimate management platform, and the Bean is the business model.
-
Core Components: bean:beanfactory,beandefinition,
Applicationcontext: inheriting beanfactory and resourceloader,core: how resources are accessed, context resource loading, parsing and description delegated to resolver
Beanfactorypostprocessor and beanpostprocessor:beanfactory and beans are initialized when Executed.
The Initializingbean and Disposablebean distributions are called when the Bean instance is created and Destroyed.
Factorybean: not a preset ball model, customized by the user
-
Features of aop: inherit factorybean, and month Java Proxy to implement dynamic proxy
-
Proxy mode: creates a proxy object for the actual object, which, when actually executed, can add additional operations to the original Object.
-
Policy Mode: There are many implementations to complete an operation, choose different implementations according to different scenarios, for example, dynamic agent has cglib,jdk proxy, and many other implementations.
The working mechanism and design pattern of Spring MVC
-
The overall design of Mvc: Dispatchservlet is the core, achieve 8 functions: initmultipartresolver processing file upload, initlocalresolver processing application Internationalization ; initthemeresolver: define a theme; inithandlermappings, request a mapping relationship; inithandleradapters, define different processing rules based on the handler type ; Inithandlerexceptionsresolvers:handler processing when error occurs; Initrequesttoviewnametranslator;initviewresolver
-
Control's overall design: handlermapping and handleradapters two components provided, handlermapping manage URL and handler correspondence, All interceptor must implement Handlerinterceptor. Handleradapter helps define a variety of handler, which are provided by default in 4 Types.
The entire invocation starts with the dispatch Doservice Method.
-
Model design: required parameters for page rendering are stored in Modelmao
-
View Design: internalresourceviewresolver Create and render Pages.
-
Template mode: Large logic is already defined, and the business only needs to implement some concrete steps, such as Spring's Abstractview
System architecture and mapping principles of Ibatis
The Fixed-invariant script Ibatis configuration is Implemented.
-
Class Hierarchy: The framework of the interaction type Client,executor,session
-
Design strategy: Parametermap and Resultmap,typehandler are responsible for type conversion
-
Operating principle: session responsible for transaction management
-
SQL Parsing: configuration file parsed into statement
-
Object Mapping: Dataexchange and Accessplan for true data mapping
-
Factory Mode: Dataexchangefactory,datasourcefactory.
How Velocity works
-
Overall architecture: mainly by the app, context, runtime, some auxiliary classes, exposed to the use of velocity and velocityengine,context encapsulated the required rendering variables
-
Parsing: parsing into JTree
-
Event Handling: empty, include, value $
-
Common optimizations: Reduce the number of tree nodes,
-
Comparison with Jsp: Parsercontroller compiling JSP into servlet,jsp dependent servlet environment, compiling execution velocity reflection execution
-
Compositing mode: partial whole mode, partial and whole implement a method to implement Sub-processing
-
Interpreter Mode: interprets text in a certain format into a specific data structure, explaining the VM as an AST abstract syntax Tree.
Velocity Optimization Practice
-
Real problems: large pages, high CPU pressure, more temporary objects, large GC impact, blank word than characters, wasted bandwidth
-
Efficient template engine: compile velocity into Java class, turn reflection into direct call, character output to byte output
-
Other methods: remove Non-chinese spaces, compress tab and line breaks, combine the same data, and render asynchronously.
Static design of large-scale navigation system
-
Java's QPS Tens of thousands of Difficult.
-
Static and dynamic distinction
-
Static selection of the scheme
Question: whether the consistency hash, whether to use esi, whether to use the physical machine, who to compress, network card selection
Share cache, split with app, back to source
-
Failure: Time-driven Passive failure, active failure: monitoring changes, Java publishing, VM Publishing
-
cdn, CDN Distribution nationwide, Active hair purge to cache failure, level two Cdn.
Thinking of frame design
-
Solve what problem, whether the existing framework can not be solved, is not better than other solutions
-
A framework for simplifying development is Needed.
-
Framework Design principles: OCP (open and close principle, extended opening, modification closed), LSP (on The Richter scale substitution, where the parent class can be used, sub-categories can be);
DIP (dependency Reversal) relies on abstraction, independent of the specific, ISP (interface isolation): interface as single as possible, CARP (synthetic/aggregation multiplexing Principle) as much as possible aggregation/composition use, not using Inheritance. LOD (dimitri principle), An object should know as little as possible about the details of other Objects.
The theoretical basis of optimization
-
Reduce the package level of the program
-
Simple procedural complications
-
Reduce the cost of translation
-
Change to be Constant.
In-depth analysis of the Java Web Technology Insider list