Preparing for Autumn Recruitment—Operating System

CPU scheduling algorithm

First-in-first-out algorithm (FIFO) : Use the CPU according to the order in which the processes are ready;

Short Process First Algorithm (SCBF) : First set a priority for each process, and determine the next executed process according to the comparative priority; appropriately increase the priority of some relatively short processes.

Time slice round-robin scheduling algorithm (RR) : assign a time slice to each process, and switch processes after running;

Virtual RR (Virtual RR) : Based on the improvement of the time slice rotation algorithm, the process that has completed the time slice will enter the auxiliary queue.

Priority Algorithm (PSA) : Each process is given a priority, and events with higher priority are more urgent and should be executed first.

The difference between threads and processes

(1) A process is the smallest unit of resource allocation, and a thread is the smallest unit of program execution

(2) The process has its own independent address space. Every time a process is started, the system will automatically allocate address space for it, and establish a database table to maintain the code segment, stack segment and data segment; threads share data in the process and use the same address space, so the cost of CPU switching a thread is smaller, and the cost of creating a thread is also smaller.

(3) Communication between threads is more convenient. Threads under the same process share data such as global variables and static variables; and communication between processes is carried out in the form of communication. Multithreading needs to solve synchronization and mutual exclusion problems;

(4) Multi-process programs are more robust. As long as one thread dies in a multi-threaded program, the entire process will die; and the death of one process will not affect the other process.

Several states of the thread

  • New (new): create a new thread,
  • Ready (runnable): call the thread start method,
  • Running (running): get cpu time slice, execute program code,
  • Blocking (block): waiting for blocking, synchronous blocking (synchronized), other blocking (sleep(), join()),
  • Dead: end the thread, or exit abnormally,
  • In fact, through the thread class, we can know that there is actually another state that is terminal (aborted);

The thread is first created by new and enters the initial state, and then the thread calls the start method to enter the ready state. It should be noted here that as long as the thread preempts the cpu time slice, it can run without acquiring all the locks, but when it runs until the required lock is not obtained, it will enter the blocking state.

When a thread is sleep, the thread will first enter the timeout waiting state, when the time is over, it will first enter the waiting blocking state, and then enter the ready state when there is a lock.

Implementation of thread pool

1. The newCachedThreadPool class creates a thread pool. If the number of threads in the thread pool is too large, it can effectively recycle redundant threads. If there are insufficient threads, it can create new threads.

2. newFixedThreadPool , this method can specify the number of threads in the thread pool. After the number is full, you need to wait in line.

3. newScheduledThreadPool , the thread pool supports timing and periodic task execution. We can delay the execution time of the task, or set a periodic time for the task to execute repeatedly.

4. newSingleThreadExecutor , which is a single thread, is executed by one thread from beginning to end.

5. ThreadPoolTaskExecutor , which is under the spring package, is the thread pool class provided by spring for us.

The rejection policy of the thread pool

1. ThreadPoolExecutor.AbortPolicy: discard the task and throw a RejectedExecutionException.

2. ThreadPoolExecutor.DiscardPolicy: discard tasks, but do not throw exceptions.

3. ThreadPoolExecutor.DiscardOldestPolicy: discard the task at the front of the queue, and then resubmit the rejected task

4. ThreadPoolExecutor.CallerRunsPolicy: The task is processed by the calling thread (the thread that submitted the task)

How threads are created

Three ways: ①Inherit the thread class, ②Realize the Runnable() interface, both rewrite the Run method; ③Create threads through Callable and Future, and implement the call method.

Generally, threads are created by inheriting the Thread class, and the Run() method is rewritten.

Seven parameters of the thread pool

corePollSize: number of core threads;
maximumPoolSize: maximum number of threads;
keepAliveTime: idle thread survival time;
TimeUnit: time unit;
BlockingQueue: thread pool task queue;
ThreadFactory: create thread factory;
RejectedExecutionHandler: rejection strategy

Workflow of the thread pool

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-RffD1BDj-1662292499415)(en-resource://database/1089:1)]

The difference between sleep and wait

They are all used for thread control. The biggest essential difference between them is: sleep does not release the synchronization lock , and it is automatically awakened by using time, which can be interrupted forcibly by interrupt(); wait releases the synchronization lock , and can be directly awakened by notify() ; sleep is a static method of the thread class. 1. These two methods come from different classes, namely Thread and Object 2. The most important thing is that the sleep method does not release the lock, but the wait method releases the lock, so that other threads can use the synchronization control block or method. 3. wait, notify and notify All can only be used in a synchronization control method or a synchronization control block, while sleep can be used anywhere.

Understanding of IOC and AOP

IOC, that is, inversion of control, leaves the creation, initialization, and destruction of objects to Spring to manage

AOP, aspect-oriented programming, uses AOP to isolate various parts of the business logic, thereby reducing the coupling degree between the various parts of the business logic, improving the reusability of the program, and improving the efficiency of development. In layman's terms, it means adding new functions to the main functions without modifying the source code.

Interface-based implementation, based on Aspectj implementation

How does the singleton mode ensure thread safety, volatile prevents instruction rearrangement

①Locking; ②The static object is initialized during class loading, and the loadClass object is locked

The difference between spring and springboot

(1) spring boot provides extremely fast and simplified operations, allowing Spring developers to get started quickly

(2) spring boot provides the default configuration for spring running

(3) spring boot provides many non-functional features for general spring projects

Mybatis's method of getting parameters and passing parameters

There are two ways to get parameters: KaTeX parse error: Expected 'EOF', got '#' at position 4: {} and #̲{}; {} is essentially string concatenation, if it is a string or date type, it needs to be used Single quotes; #{} is essentially a placeholder assignment. If it is a string type or a date type, single quotes can be added automatically.

Parameter passing: ① order passing, ② @Param passing parameters, ③ map collection passing parameters, ④ JavaBean entity class passing, ⑤ collection type parameter List passing.

Bean injection method

1) Autowired injection method, (2) constructor injection, (3) @Bean method parameter injection, (4) directly use @ConfigurationProperties (prefix="jdbc") on @Bean method

The execution flow of springMVC

1) The user sends a request to the server, and the request is captured by the springmvc front controller dispatcherSevlet

2) DispatcherServlet parses the request URL, obtains the request resource identifier, and determines the mapping corresponding to the request URL.

3) According to the URL, call HandlerMapping to obtain all related objects configured by the Handler (including the Handler object and the interceptor corresponding to the Handler object), and finally return it in the form of a HandlerExecutionChain execution chain object.

4) DispatcherServlet selects a handlerAdapter based on the obtained handler.

5) If the HandlerAdapter is obtained successfully, the preHandler() method of the interceptor will be executed at this time

6) Extract the model data in the request, fill in the Handler input parameters, start executing the Handler (Controller) method, and process the request. In the process of filling Handler's input parameters, according to your configuration, Spring will help you do some extra work.

7) After the Handler is executed, return a ModelAndView object to the DispatcherServlet

8) At this point, the interceptor's postHandler() method will be executed

9) According to the returned ModelAndView, select the appropriate ViewResolver to try to resolve, and render the view according to the Model and View.

10) After rendering the view, execute the afterCompletion() method of the interceptor.

11) Return the rendering result to the client.

What is serialization and reflection, serialization interface implementation

Reflection means that the internal information of any class can be obtained through the reflection API when the program is running, including modifiers, variable types, return types, fields, methods, etc., and fields and wake-up methods can be changed at runtime.

Serialization is a mechanism for processing object streams. The so-called object stream is to stream the content of objects. In order to solve the problems caused by reading and writing operations on objects.

Implementation of serialization: The class that needs to be serialized implements the Serializable interface. This interface has no methods that need to be implemented. implements Serializable is just to mark that the object can be serialized, and then use an output stream (such as: FileOutputStream) to construct An ObjectOutputStream (object stream) object, and then use the writeObject(Object obj) method of the ObjectOutputStream object to write out the object whose parameter is obj (that is, save its state), and use the input stream to restore it.

Three major features: encapsulation, inheritance, and polymorphism

1) Encapsulation refers to hiding the state (properties) of an object inside the object, and does not allow external objects to directly access the internal information of the object. But it is possible to provide methods that can be accessed externally to manipulate attributes.

2) Inherit and expand existing code modules for code reuse.

3) Polymorphism: The compile-time type of the object is inconsistent with the runtime type, which is specifically manifested in that the reference of the parent class points to the instance of the subclass. Java reference variables have two types (compile-time type and runtime type). Among them, the compile-time type is determined by the type used when declaring the variable (parent class), and the runtime type is determined by the object actually assigned to the variable (subclass).

list、set、map

Linear table, set (cannot be repeated), map is of kv type

Interfaces and Abstract Classes

(1) Abstract classes must be inherited by subclasses, and interface classes must be implemented by classes

(2) Interfaces can only be declared as methods, and abstract classes can be implemented as methods

(3) The variables defined in the interface can only be public static constants, and the variables in the abstract class are ordinary variables

(4) Interface is the result of design, abstract class is the result of refactoring

(5) Both abstract classes and interfaces are used to abstract concrete objects, and interfaces have the highest level of abstraction

(6) Abstract classes can have specific methods and attributes, while interfaces can only abstract methods and immutable constants

(7) Abstract classes are mainly used to abstract categories, and interfaces are mainly used to abstract functions

Changes in jdk1.7 and 1.8

The Default keyword is used in the interface to define the method body, and the implementation class can be called directly.

Lambda expression, functional programming, a programming paradigm with a high degree of abstraction, and a pure functional programming language to write functions without variables.

Functional interface, local variable restrictions.

The difference between arrays and lists

(1) The types are different, and the array list is very similar to the array, but the capacity of the array list can be changed dynamically, so the array list is also a frequently used type among the collection types. Array and ArrayList

(2) The elements are different, the Array array can contain basic types and object types, while the list ArrayList can only contain object types. However, the elements of data storage are all of the same type, but the array list is different, and can store Object objects.

Guess you like

Origin blog.csdn.net/hallobike/article/details/126693590