This article introduces three points:
1. Comparison of Single-thread and multi-thread
2. Two Methods for creating multithreading: 1. extends Thread 2. implements Runnable
Iii. Thread Synchronization
1. Comparison of Single-thread and multi-thread
1. Single thread
TestThread. java
public class TestThread {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubnew Thre
*********************************************** Declaration *********************** *******************************Original works, from the "Xiaofeng Moon XJ" blog, Welcome to reprint, please be sure to indicate the source (HTTP://BLOG.CSDN.NET/XIAOFENGCANYUEXJ).Due to various reasons, there may be many shortcomings, welcome treatise!*************** ******************************************************************************************recently, because of the reasons for the work, the system
E.printstacktrace () ; }} System.out.println ("Productor5 End:has put units" Each thread is started by 1s, and the resultBlockingqueue now contains 0 unit Consumer1 start:need units Blockingqueue now contains 0 unit Productor2 start:put 5 Units Productor2 End:has put 5 units Blockingqueue now contains 0 unit Productor3 start:put 5 units Productor3 End:has Put 5 units Consumer1 End:has got units Blockingqueue now contains 0 unit PRODUCTOR4 start:put [units Productor4] End:has put units block
auto-generated Method StubSystem.out.println ("Productor5 start:put units"); for(inti = 0; I ){ Try{blockingqueue.put ("Object"); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }} System.out.println ("Productor5 End:has put ten units"); } }Each thread is started by 1s, and the resultBlockingqueue now contains 0 unitConsumer1 start:need UnitsBlockingqueue now contains 0 unitProductor2 Start:put 5 UnitsProductor2 End:has put 5 unitsBlockingqueue now co
variables and thread safetyInstance variables in a custom thread class can have shared and unshared points for other threads.3.1 Do not share data3.2 Sharing data4. Be aware of i--and System.out.println () anomaliesThird, CurrentThread () methodIv. isAlive () methodV. Sleep () methodVi. getId () methodSeven, stop the thread1. Threads that can't be stopped2. Determine if a thread is in a stopped state3. Can stop the thread--exception method4. Stop in slumber5. The thread that can stop--the viole
, in the programming language, threading can be a love-hate paradox for programmers, which can greatly simplify the model, help programmers write powerful code, and, on the other hand, make our programs appear with a variety of bugs that can be difficult to reproduce in the development environment.
Here the author based on the "Java Core technology" book and some Bovinlai to share with you on
Java _ multithreading _ producer and consumer (concurrent collaboration), java producer
For multi-threaded programs, regardless of any programming language, producer and consumer models are the most classic. Just like learning every programming language, Hello World! Are the most classic examples.In fact, it should be accurate to say that it is the "producer-cons
Recently in the study of the JVM, found that with the virtual machine at the bottom of the understanding of Java multithreading also has a new understanding of the original a small synchronized keyword in the Shia. decided to put their own Java multi-threading learning into an article, from the most basic why use multi-threading, has been deeply explained to the
threads are rerun; Countdownlatch is not, after a thread has run to a point, it just gives a value of-1. The thread continues to run(2) Cyclicbarrier can only evoke one task, countdownlatch may evoke multiple tasks(3) Cyclicbarrier Reusable, countdownlatch non-reusable, count value 0 The Countdownlatch is no longer usable6, the role of volatile keywordsA very important problem is that every Java programmer who learns and applies
I seriously probation the book today, first of all, according to the author's habit of reading, like to look at the front of the first part. In the preface, the author put a road map of learning Java, which is a standard learning process. But why put a design pattern in the programming advanced, and then the next is the abstract class and interface, package and access rights (this name and
The first part of this article has aroused some readers' interest. Some readers share the same feeling with me about "many ordinary readers are still at a loss in the face of books" and ask how to choose books to buy books. In fact, I have been asked the same question for many occasions, including forums and technical lectures. Therefore, before continuing to introduce a good Java book, I would like to expl
in Java multithreaded applications, queue usage is high, and the preferred data structure for most production consumption models is the queue. Java provides thread-safe queues that can be divided intoblocking queues and non-blocking queues, where the typical example of a blocking queue is blockingqueue, a typical example of a non-blocking queue is concurrentlinkedqueue, which, in practice, chooses a blockin
) After a thread of cyclicbarrier runs to a point, the thread stops running until all the threads have reached the point and all the threads are rerun; Countdownlatch is not, after a thread has run to a point, it just gives a value of-1. The thread continues to run(2) Cyclicbarrier can only evoke one task, countdownlatch may evoke multiple tasks(3) Cyclicbarrier Reusable, countdownlatch non-reusable, count value 0 The Countdownlatch is no longer usable6, the role of volatile keywordsA very impor
until now, the Java Series tutorial has been updated. Content covered: Javase basic knowledge points, UML modeling, unit testing and so on. I want to be able to help a friend who wants to learn the Java language. in the process of writing, there will inevitably be some mistakes, I hope you can make a lot of suggestions. Because this book is from the author Csdn b
Starting from this article, I will conduct an in-depth analysis on Java multithreading. This is a large part of the content, and it is also a hurdle that we must cross as Java developers! Because Java itself is a multi-threaded language, to really master Java, Please Master
Java Multithreading Beginner's Guide (1): Threading Introduction
Java Multithreading Beginner's Guide (2): Creating Threads with the thread class
Java Multithreading Beginner's Guide (3): Creating a thread using the Runnable i
Java Multithreading (i)
Multithreading as a very important point of knowledge in Java, this is still necessary to sum up.
I. Thread life cycle and five basic states
For the life cycle of the Java thread, first take a look at the more classic diagram below:
The above di
. Multithreading
Java introduces the virtual processor technology, which combines thread support with the language runtime environment. Regardless of the system, Java provides the ability to execute multiple tasks concurrently, the comprehensive support for multithreading is also an important feature of the
Preface
Recently found that sometimes after reading a book, time is easy to forget, reading does not summarize the effect of a large discount, it is intended to write this series of articles, one is to tidy up the main points in the book, to help their digestion and understanding; the second is to encourage themselves to read more thinking. The article will not explain the contents of the
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.