JAVA intermediate developers should have little knowledge

A pessimistic locking, optimistic locking difference:

Pessimistic locking : perform logical plus some pessimistic locks, different threads simultaneously execute only one thread can execute other threads wait at the entrance until the lock is released.
Optimistic locking : period of execution logic coupled with optimistic locking, different threads execute simultaneously, you can enter simultaneously executed at the last time check whether these data with new data is modified by other threads,
( whether the same early version and execution ), no modifications made with the new You have to give up this operation.
// 0 begin transaction
begin; / begin work; / start transaction; ( three can be selected from a)
// check out an item information.
SELECT Status from t_goods WHERE ID = 1 for Update;
// 2 according to the commodity information generating order
INSERT INTO t_orders (ID, goods_id) values (null,. 1);
.. 3 // product Review status to 2
Update t_goods SET status = 2;
. //. 4 commits the transaction
commit; / commit work;


1. check out merchandise information
SELECT (status, status, Version) from t_goods WHERE ID = # {ID}
2. The product information generating line
3. Product Review status to 2
Update t_goods
SET status = 2,. 1 + Version Version =
WHERE id = # {id} and version = # {version};


 

Two .mysql optimization:

1. Try to avoid full table queries, indexing behind where and order by

2. Try to avoid using the back where conditions! = And <> operators, otherwise it will cause the engine to give up and go full indexing table query

3. make use of numeric fields, not designed as a character field ,, this will reduce the query and link performance, and increases storage costs
because the engine when processing queries and links one by one each character string comparison, while For numeric only once


 

Three thread pool:

Creating a thread in a multithreaded program initialize collection, then you need to perform new tasks when these threads reuse rather than create a new thread.

Benefits:
1, the thread pool to improve the response time of an application. As the threads in the pool is ready and waiting to be assigned tasks, the application can be directly used without using a new thread.

2, saving the CLR thread pool thread to create a complete short life cycle for each task overhead and resources can be recovered after the task is completed.

3, the thread pool thread time slice is optimized according to processes that are currently running on the system.

4, the thread pool allows us to open multiple tasks without having to set the properties for each thread.

5, the thread pool allows us to pass an object that contains status information for the program parameters of the task being performed reference.

6, the thread pool can be used to limit the maximum number of threads to solve a specific problem processing the request.


 

Four .JVM inside the concept:

1, Java virtual machine stack:

Private thread; each method when executed creates a stack frame, the local variable table is stored, the operand stack, dynamic linking, return address method; each method call from the completion of the execution,
a corresponding stack frame in a virtual machine stack pushing and popping.

2, the heap:
thread shared; shared by all threads in a memory area created when the virtual machine is powered on, used to store an object instance.

3, method area:
shared among threads; shared by all threads of a memory area; means for storing the virtual machine has been loaded class information, a constant, static variables and the like.

4, the program counter:
thread private; bytecode line number indicators currently executing thread, each thread must have a separate program counter, this type of memory is also referred to as "thread private" memory.

5, native method stacks:
thread private; mainly for the virtual machine to use a method of Native service.


 

Five .TCP three-way handshake

TCP three-way handshake:
three-way handshake is to establish a TCP connection, the client and server which sent a total of three packets to determine whether to establish the connection. In socket programming performed by the client
to trigger connect.

TCP three-way handshake .png
(1) The first handshake: Client SYN flag bit is set to 1, a randomly generated value seq = J, and the packet is sent to the Server, Client enters the SYN_SENT state,
waiting for acknowledgment Server.

(2) The second handshake: Server receives the packet data from the flag bit SYN = 1 know Client requests to establish a connection, Server SYN and ACK flag bit are set to 1, ack = J + 1,
to generate a random value seq = K, and transmits the data packet to acknowledge a connection request to the Client, Server enters SYN_RCVD state.

(3) third handshake: the Client receives acknowledgment, checking whether the ack J + 1, ACK is 1, then if the correct ACK flag is set to 1, ack = K + 1, and the data
packet transmission to Server, Server checks whether the ack K + 1, ACK is 1, if correct, the connection is established, Client and Server enters eSTABLISHED state,
complete the three-way handshake, then you can begin to transfer data between Client and Server.

Simply put,

1, a connection is established, the client sends a SYN packet (SYN = i) to the server, and proceeds to SYN-SEND state, waiting for the server to confirm

2, the server receives a SYN packet, must confirm the customer SYN (ack = i + 1), while themselves sends a SYN packet (SYN = k), i.e., SYN + ACK packet, then the server enters a state SYN-RECV

3, the client receives the SYN + ACK packet to the server, the server sends an acknowledgment message ACK (ack = k + 1) , this packet is sent, the client and server into the ESTABLISHED state,
complete the three-way handshake, the client and the server begins transmitting data.


 

Four waving .png six .TCP

Since the TCP connection is full-duplex, thus, each direction must be shut down separately, this principle is that when one task is finished sending data, sending a FIN to terminate this direction
connection means only receives a FIN There is no data on the flow in that direction, that is no longer receive data, but still be able to send data over the TCP connection,
until this direction also send a FIN. To shut down one of the first active close, while the other performs a passive closed, the description is the case of FIG.

(1) First Wave: Client sends a FIN, for closing the data transfer Client Server tenderer, Client enters FIN_WAIT_1 state.

(2) Second wave: Server receives the FIN, ACK to send a Client, the acknowledgment number for the receipt number +1 (the same SYN, FIN a occupy a sequence number),
Server enters CLOSE_WAIT state.

(3) Third Wave: Server sends a FIN, for closing the Client Server data transfer, LAST_ACK Server enters state.

(4) Fourth wave: the Client receives the FIN, Client enters TIME_WAIT state, and then sends an ACK to the Server, for the receipt of the acknowledgment number number + 1, Server enters the
CLOSED state, four complete wave.


七.Kafka、ActiveMQ、RabbitMQ、RocketMQ

General business systems to be introduced MQ, the earliest we all use ActiveMQ, but now we do not much use, no proven large-scale throughput scene, the community is not very active,
so we still forget it, I personally do not We recommend the use of this;

Later, it began to use RabbitMQ, but it does prevent a lot of erlang language Java engineers go in-depth study and control it, for companies, almost in an uncontrollable state,
but people are really open source, relatively stable support activity also high;

But now more and more companies will indeed go with RocketMQ, really good, after all, Ali produced, but the risk community may have suddenly lost the yellow (currently RocketMQ
has been donated to Apache, but activity is actually not high on GitHub ) have their own technical strength absolutely confident, recommended RocketMQ, otherwise go back and honestly with
RabbitMQ it, others have an active open source community, will not yellow.

So small and medium companies, technical strength is more general, the technical challenges are not particularly high, with RabbitMQ is a good choice; large companies, infrastructure, strong R & D strength,
with RocketMQ is a good choice.

If it is calculated in real time big data field, log collection and other scenes, with Kafka is the industry standard and is definitely no problem, a high degree of community activists, will not yellow, not to mention
almost the whole world is the fact that sexual norms in this field.


 

Eight .HashMap source parsing (jdk1.8):

HashMap structures began to appear in jdk1.2, jdk1.7 has not been to too many changes in 1.8 there is a big change
jdk1.7: Array + (high efficiency additions and deletions) list
jdk1.8: array + + red and black list ( query efficiency also becomes faster)

Only red-black tree in the chain length of not less than 8, and the array length is not less than 64 can be converted to red-black tree

What is the red-black tree: a self-balancing binary search tree, that is more efficient query red-black tree


Nine singleton:

Example lazy single

public class Singleton {
private static Singleton singleton = null;
private Singleton(){
}
public synchronized static Singleton getSingleton(){
if(singleton == null){
singleton = new Singleton();
}
return singleton;
}
}

 

Single starving Example:

public class Singleton {
private static final Singleton singleton = new Singleton();
private Singleton(){
}
public static Singleton getSingleton(){
return singleton;
}
}

 

Java Singleton pattern major role is to ensure that a Java application, a Class of only one instance of existence. The benefits of using Singleton is also to save memory,
because it limits the number of instances is conducive to Java garbage collection


Ten .sql exists and not exists in usage:

exist: to emphasize that the result set returned without demanding to know what is returned (exists clause do not care what the return, but care is not a returned result set)

exists in the biggest difference is that in the guide clause can only return a field, such as:
SELECT name from Student WHERE Sex = 'm' and in Mark (SELECT ... WHERE Grade from l, 2,3)

, in the sub- sentence returned three fields, which is not true, exists clauses are allowed, but in return allows only one field, in the two fields 2, 3, just go to.


Eleven .SOA: SOA also known as service management, help us to service calls between the system of governance up

Uniform standards: each system protocol, address, interactively.
New interactive way: each system separately in accordance with uniform standards to the registration data bus, when various subsystems call other subsystems, we do not care if it finds other subsystems,
we only recruit data bus, a data bus and then find other according to uniform standards subsystem, the data bus, which acts as a passer-only role.

SOA benefits:

1, reduce user costs, users do not care what language between the various services, do not need to know if you call them, just need to find a unified standard data bus through it.

2, a simple relationship between Service

3, identify which programs have problems (hang)

Cons: Tip the corresponding affect the system's complexity, performance.

Currently there are application data bus Ali dubbo, there zookeeper.

 

 

 

Guess you like

Origin www.cnblogs.com/Cjx-605/p/11422435.html