2018 Week 18 Summary

MyBatis cache design

It is a note of several articles related to caching in "In-depth Understanding of MyBatis Principles" on the Internet. Through MyBatis's understanding of the design of the cache SPI interface, first-level and second-level caches, you can learn from this when using caches in later projects or designing caches for basic frameworks. Good ideas inside. At the same time, as a very common technology, caching is used to compare and analyze the applications in the project, which is also convenient for better technology selection in the future.

SpringMVC request parameter annotation two small problems

Recorded two simple problems encountered in the project. When the @requestBody annotation is used before the parameters of the Java object type, the content of the request body requires that the content of the request body be converted into json or other types that can be converted into java objects through the message converter, not form -data mode for uploading files, otherwise the unsupported media type will be wrong;
@requestParam is used to handle Content-Type: content encoded for application/x-www-form-urlencoded. (In the Http protocol, if Content-Type is not specified, the parameter passed by default is application/x-www-form-urlencoded type) RequestParam can accept simple type attributes or object types.  The essence is to configure the Key-Value parameter Map in Request.getParameter() using Spring's conversion mechanism, ConversionService, and convert it into a parameter receiving object or field.

gcRoot and reference types in Java

GcRoots is a set of root references that Java searches for reachable object references, which may be local variables in the virtual machine, class static variables in the method area, always-on objects, or local method objects in the local method stack.

The choice of multi-process and multi-thread

Process is the unit of operating system resource allocation, sharing resources is inconvenient and does not require synchronization; thread is the basic unit of scheduling execution, sharing resources is convenient, but the synchronization operation is complicated. Generally, applications with intensive computing and frequent switching will choose the multi-threaded model, while applications that pursue stability and reliability (failures do not affect each other) can use the multi-process model.

Talk about the Java happens-before principle

In order to ensure the normal execution of the program, the hardware, JVM, and compiler must abide by the Happ-before principle when optimizing Java programs.

  1. The execution results in a single thread and the execution results in the order of code writing remain unchanged;
  2. For a locked object, the unlock operation must be performed before the lock operation can be obtained again;
  3. The write operation of a volatile variable occurs first with the read operation of this variable;
  4. Transmission rule, operation A precedes B, B precedes C, then A must happen before C;
  5. The start method of the thread object is executed before each action in the thread;
  6. The interrupt operation of the thread object occurs before the thread detects the occurrence of the interrupt event;
  7. The operations in the thread object are all terminated before the object;
  8. The initialization of an object is performed before its finalize method;

Singleton Pattern in Java

Singleton is a common but difficult pattern in Java. The singleton pattern is generally a class that creates its own instance and provides it to the outside world. At the same time, it has a private constructor that does not allow the outside world to create its instance. The outside world creates instances through clone, reflection, and serial deserialization mechanisms. It is generally recommended to use the enumeration method.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325339278&siteId=291194637