First, how to achieve multi-threading
Implementing the Runnable Interface
1 Public Static voidMain (string[] args) {2MyThread MyThread =NewMyThread ();//A class that implements the Runnable interface3Thread T =NewThread
There are three ways to create threads: one is to inherit the thread class, the other is to implement the Runnable interface, and the third is to create threads using callable and future.Inheriting the thread class to create threads Steps:
Turn from: JAVA notes callable and Futuretask: Multithreading with return valuesThe commonly used thread class has no return value after the Run method executes, and a third-party dump is required to implement the return value to the main thread
ObjectiveIn the previous Java Fundamentals Review, we reviewed the underlying data types, modifiers and strings, three features, collections, multithreading, and Io. This article summarizes the knowledge that you have previously learned. In addition
Java Multi-Threading in the development of a lot of use, a simple summary of several methods, respectively, is to inherit the thread method, realize runnable interface, realize callable interface;1. Inheriting the thread methodclass TestThread
1.Volatile and synchronized different points(1), volatile can only be used for variables, the use of a small range. Synchronized can be used in variables, methods, classes, synchronous code blocks, etc., the scope of use is relatively wide.(2),
Three ways and differences in Java implementation threadsJava three ways to implement threads:
Inherit thread
Implementing the Runnable Interface
Implementing the Callable Interface
Difference:
The first way to inherit
http://blog.csdn.net/pipisorry/article/details/44341579IntroductionThe callable interface represents a piece of code that can be called and returns the result;The future interface represents an asynchronous task, which is the result of a task that
PackageTestA;Importjava.util.concurrent.Callable;Importjava.util.concurrent.ExecutionException;ImportJava.util.concurrent.FutureTask; Public classThreadTest { Public Static voidMain (string[] args) {//1. Inheriting the thread class
There is a scenario in which sending data to a server with multithreading requires knowing that each thread is sent successfully, and all threads are sent to finish before the next round of calculations and sends. If you use traditional
One, there are three main ways to create threads in Java:1. Inherit the thread class to create a threading class(1) Define a subclass of the thread class and override the Run method of the class, which represents the task that the thread will
Multithreading is a very important Java knowledge point, in this small series for everyone to summarize Java thread Multithreading, very useful, I hope you can master Oh.
I. Thread life cycle and five basic states
For the life cycle of the Java
First, the basic concept of multithreadingExclusive: Maintains state consistency by blocking harmful interference between multiple concurrent behaviors. Asynchronous methods are usually used sychronizedState dependency: Triggering, blocking,
The difference between a process and a threadTotal: The operating system performs multiple tasks, each task is a process, the process performs multitasking, each task is a thread;Part1. Scheduling: In the introduction of the thread of the OS, the
In the threading model of the hotspot VM, Java threads are mapped one-to-one to local operating system threads. The Java thread creates a local operating system thread when it is started, and the operating system thread is reclaimed when the Java
1. The difference between the daemon and local threads in Java.
There are two types of threads in Java: The daemon thread (Daemon) and the user thread.
Any thread can be set as a daemon thread and a user thread, by method Thread.setdaemon (bool on)
Multithreading as a very important point of knowledge in Java, there is still a need to summarize.I. Thread life cycle and five basic statesFor the life cycle of the threads in Java, first look at this more classic diagram:Basically includes all the
The traditional way of implementing threads is three, inheriting the thread class, overriding the run () method, implementing the Runable interface, overriding the run () method, implementing the callable interface, overriding the call () method,
a . the life cycle of threads and five basic statesJava thread has v basic Statenew State (new): When the thread object pair is created, it enters the new state, such as thread t = new MyThread ();ready State (Runnable): When the Start () method
Java multithreading implementation
Java Virtual Machine allows applications to run multiple threads concurrently. In java, multithreading is implemented in the following three methods:
1) Implement the Runnable interface and implement the run ()
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.