Thoroughly understand Java's multithreading-Inter-thread communication (2)-Linux general technology-Linux programming and kernel information. The following is a detailed description. 2.4 differences between sleep () and yield ()
1) sleep () causes
1.There are two ways to implement multithreaded operations in Java: Inheriting the thread class and implementing the Runnable interfaceFirst, inherit the thread classClass MyThread extends Thread {//Inherit thread classprivate String name;Public
Background
Because using the Stop method to stop a thread from being very violent can cause a series of problems, a gentle approach is proposed: Ask the other one not to execute, which is the interrupt mode.
There is also the scenario
Go to: http://blog.csdn.net/anhuidelinger/article/details/11746365
Three ways to terminate a threadThere are three ways to terminate the thread.1. Use the exit flag to cause the thread to exit normally, that is, the thread terminates when the Run
Thread Concession: Yield ()the role of yield () is to give in. It allows the current thread to move from "Run state" to "ready state", this allows other waiting threads with the same priority to get execution rights, but there is no guarantee that
Thread Start:Description of the difference between 1.start () and run ()start (): Its function is to start a new thread, the new thread will execute the corresponding run () method. Start () cannot be called repeatedly.Run (): Run (), like a normal
[This is my own study notes, welcome reprint, but please specify the source:http://blog.csdn.net/jesson20121020]
Socket Communication:The two programs on the network implement data interaction through a two-way communication connection, one end
(i) Mutual exclusionMutex, or atomicity. Atoms, refers to the smallest matter, the specific non-division of the.In CPU operation, the time slice of multi-threading is executed, and one block executes, which satisfies the atomicity of mutex.Ways to
Java thread shutdown, in general there are 3 kinds:
1. Use state bit, this simple, do not say more:
Copy Code code as follows:
public class Task extends Thread {
Private volatile Boolean flag= true;
public void Stoptask () {
Creating ThreadsA thread represents a separate execution flow that has its own program execution counter and has its own stack. Below, we create a thread to establish a visual sense of threads, in Java to create a thread in two ways, one is to
Today casually wrote a program between threads scheduling each other, the code is as follows:Class First extends Thread{public first () {Start ();} Synchronized public void Run () {try{wait ();} catch (Interruptedexception e) {e.printstacktrace ();}
Thread communication is used to ensure that threads are coordinated, and it is generally necessary to consider the problem of thread communication when doing thread synchronization.
1. Traditional thread Communication
Typically, the three methods
Stop threads are not as Break,return in the Java language as they are, and require some skill.
The thread's stop was thought to be simple, a interupt () method was done, and in fact it was completely wrong, and the thread's Stop API did provide a
PipedOutputStream and PipedInputStream
In Java, PipedOutputStream and pipedinputstream are pipe output streams and pipe input streams respectively.Their role is to allow multithreading to communicate between threads through the pipeline.
Prior description:Andoran teeth need to locate the right to apply, in the Android 6.0 users need to manually confirm the right to use, you can query the data to achieve, if it is troublesome, you can use the Third-party Bmob Integrated tool class
First, thread communication (producer consumer issues):1, Thread communication: a thread to complete its own task, to notify another thread to complete another task.
2, the Classic question : producer and consumer issues.1 There is a thread safety
[Multithreading] _ multi-thread notes
Objectives of this chapter:Measure the test taker's knowledge about the differences between processes and threads.Understanding the two implementation methods and differences in Java threadsUnderstanding the
Java multi-thread design model Reading Notes 4 -- two-phase termination
In the two-phase termination mode, the thread ends normally, that is, some aftercare is performed before the end, and the released resources are released to complete the
We all know that before jdk1.5, Java usually requires programmers to complete code implementation independently. Of course, some open-source frameworks provide these functions, however, these functions are not provided by JDK for ease of use. When
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.