Multithreading Concepts in Java

Source: Internet
Author: User

1. If the program has only one execution path, then the program is a single threaded procedure.

If the program has multiple execution paths, then the program is a multithreaded program.    2. Threads are dependent on the process and exist. And the process is the running program. The system is a separate unit for resource allocation and scheduling. Each process has his memory space and system resources. 3. Single-process computer can only do one thing: dos command window now the computer may do multiple things. Multiple processes are supported and the CPU usage can be increased. 4. A thread is a process that can perform multiple tasks, each of which is a thread thread that is the execution unit of the program, the execution path, and the most basic unit of the CPU used by the program. 5. The existence of multithreading, not to improve the execution speed of the program, is to improve application usage, thread is the execution is random 6.Concurrency: Physically occurring at the same time, a certainPoint in TimeRun multiple programs at the same timeParallel: Logically occurring at the same time, a certainin TimeRun multiple programs at the same time 7.        How the Java program works: · Starting a JVM,JVM startup by a Java command is equivalent to starting a process. The process then creates a main thread to call the Main method when the JVM virtual machine is started multithreaded, because there is a garbage collection thread to start, or a memory overflow occurs. 8. Interview: The difference between the run and start methods: The Run method: just encapsulate the code executed by the thread, the direct call is the normal method of the Start method: The first is to start the thread, and then by the JVM to call the thread's Run () method 9.IllegalThreadSt ATE Exception: Illegal thread state exception description the same thread cannot be called two times. 10. Get the name of the thread:The name of the object. getname ();set the name of the thread: object name. SetName (); Gets the name of the thread object of the main method (not the name of the threads subclass):Thread.currentThread.getname ();11. Get the default priority:The name of the object. GetPriority (); The default priority is 5. 12. Set Priority: Object name. setpriority (int newpriority); if the int type is notmin-priority (1)Ormax-priority (Ten), the illegal ArgumentException error is reported, which means that an illegal or incorrect parameter value is passed in. Note: Because the thread has randomness, run one or two times can not see the result, must run more than a few times. 13. (1) Daemon thread:The name of the object. Setdaemon (Boolean on)This method is called before the thread is started. (2) Join thread:The name of the object. Setjoin ()To get that thread to execute first, add the method after the boot thread and try, catch. (3) Open Thread: Object name. Start () (4) Break thread: Object name. Stop () is deprecated and deprecated: object name. Interrupt (), it will go Tay,catch reported an exception, and does not affect the execution of the following code 14. Synchronization problem: (1) Multiple threads (2) are using the same lock object (arbitrary Objects, create a casual one) benefits: solve the problem of multi-threaded security: When the thread is quite a lot of time, because each thread will judge the synchronization of the lock, very expensive resources, virtually reduce the efficiency of the program running. 15. Synchronous resolution of thread safety A. Synchronizing code block synchronized (object) {code that needs to be synchronized}arbitrary Objects, create a B for yourself. The synchronization method adds synchronization to the method where the lock object is Thisc. The static synchronization method adds synchronization to the method where the lock object is the current class's bytecode file object (class name). Class) 16. For thread-safe classes (1) stringbuffer (2) Vector (3) Hashtable How to turn a thread-unsafe collection class into a thread-safe collection class with Colle Methods for Ctions tool classes

Multithreading Concepts in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.