Java BASICS (22) thread (1), java basics thread
Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!
It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!
Also very welcome to my blog to watch blog address: http://www.cnblogs.com/duscl/
/* 1: multithreading (comprehension) (1) multithreading: an application has multiple execution paths. Process: The application thread being executed: The Execution Unit of the process. The execution path is single thread: an application has only one execution path and multiple threads: Does an application have multiple execution paths and multiple processes? What is the significance of improving CPU usage by multithreading? Improve Application Usage (2) How Java programs run and does JVM start multithreading? A: run the Java command to start JVM. JVM starts A process that starts A main thread. B: JVM startup is multi-threaded, because it has two threads at least, the main thread and the garbage collection thread. (3) multi-threaded Implementation Scheme (completing steps and mastering code by yourself) A: Inheriting Thread class B: Implementing the Runnable interface (4) Thread scheduling and priority issues: thread Scheduling a: time-based scheduling B: preemptible Scheduling (Java adopts this scheduling mode) B: Get and set the thread priority a: The default value is 5 B: the range is 1-10 (5) thread control (common method) A: Sleep thread B: Add thread C: courtesy thread D: Background thread E: Terminate thread (master) (6) thread life cycle (refer to the line Life Cycle Graph to extract .bmp) A: create B: Ready C: Run D: Block E: death (7) Implementation of the cinema ticket selling program: inheriting Thread class B: Implementing the Runnable interface (8) cinema ticket selling program has A problem. A: to better suit the real scenario, sleep for 100 milliseconds is added. B: Ticket Selling problem a: Same ticket multiple times B: Negative ticket (9) the cause of the multi-thread security problem (which is also the basis for us to determine whether A program has a thread security problem in the future): multi-threaded environment B: Shared data C: Multi-statement operations shared data (10) Synchronization solves thread security issues A: Synchronous Code block synchronized (object) {code to be synchronized;} the lock object here can be any object. B: add the synchronization method to the method. The lock object here is this C: The static synchronization method adds synchronization to the method. Here, the lock object is the bytecode file object of the current class (reflection and then the bytecode file object) (11) Review the previous thread-safe class A: StringBuffer B: Vector C: hashtable D: how to change a collection class with unsafe threads into a collection class with thread security using the methods of the Collections tool class. *\