Java foundation multithread 2[thread control]

Multi thread 2[thread control] 1.Thread scheduling and setting thread priority (1).Two models of thread scheduling A:In the time-sharing scheduling model, all threads take turns to use CPU usage and allocate the time slice of each thread occupying CPU. B:The preemptive scheduling model gives priority to the use of CPU by high priority threads. If the priority is the same, then at this time a randomly selected CPU is obtained by high priority threads. The time slice is relatively small. javaThe preemptive scheduling model is used. (2).thread priority A:Get priority of thread public f...

Java foundation multithread 1[thread introduction and first multithreaded program]

Multithreading 1.Introduction of multithreading If there is only one way to execute the program, the program is a single threaded program. If there are multiple ways to execute, then changing the program is multithreading. 2.Process overview and multi process significance If you want to know the thread, you must understand the process first, because the thread is dependent on the process. (1).What is a process? It’s the running application. It is an independent unit for resource allocation and scheduling. Each process has its own memory space and system resources. (2).What i...

[Java] learning – memory overflow experience

【Https://www.toutiao.com/i6595365358301872643/ Preface OutOfMemoryError Problem I believe many friends have encountered, compared to common business anomalies (array boundaries, null pointers, etc.) such problems are difficult to locate and solve. This paper focuses on the location and solution of a recent online memory overflow problem, hoping to bring ideas and help to students who encounter similar problems. Mainly from the performance of –> check –> locate –> solve four steps to analyze and solve problems. Appearance Recently, an application on our production ...

Java basis — Methods with parameters (two)

1. package demo2; public class Zhazhziji1 { public String zhazhi(String fruit){ String juice=fruit+” > watermelon >“); System.out.println(juice); } } 1. ><>) {                // >: public class StudentsBiz { String[ ] names = new String[30]; public void addName(String name) { // > . parameters2, traverse array in song style students[i]=name; break; } } }  // > public boolean find(int begin,int end,String name){ boolean rs=false; for (int i = begin; i < end; i++) { if (students[i].equals(name)) { rs=true;     break; } } return rs; } }     package demo...

Java foundation — no reference method for classes

1. > method Two cases returns the type of the return value. public String color; // > return value. //return > no return value.      al.run();      // >: Give an example public class AutoLion {       // > attributefile > calls another method in one method. public String info(){ return “ > callStudent“b( ) > callb( ) } 2.Student“a( ) > callTeacher“b() }   Example: the student method calls the teacher method.         6.“ TestCell > charging.…”); } } public class CellTest { public static void main(String[] args) { Cell nanfu=new C...

The art of concurrent programming for Java (notes)

Threads have overhead time for creation and context switching, and all single-threaded programs are not necessarily slower than multithreaded execution times. (the shorter the execution time is, the more obvious it is).     In imperative programming, there are two communication mechanisms between threads: shared memory and message passing. In shared memory concurrency model, threads share common status. In message passing concurrency model, messages must be displayed between threads. Synchronization must be displayed in the shared memory model, such as synchronized, and synchronization is i...

Java multi thread programming core technology (notes)

Multithreading is asynchronous (asynchronous, i.e., synchronized, ReentrantLock, etc.), and the time when the thread is called is random.   There are two ways to use multithreading: inherit Thread and implement the run method under Runnable interface. ThreadThe class implements the Runnable interface, which has polymorphic relationships. A thread is a sub task, and CPU runs in an uncertain way.   Thread.startMethod tells the thread planner that the thread is ready to wait for the run method of the thread object to be called. If the Thread.run method is invoked, it is not executed asynchrono...