This blog post is based on the previous blog article. Questions about the previous blog:
It is recommended that you read the problem first Background: http://blog.csdn.net/xinwang24/article/details/7311944
There are two solutions I have tried. The
First write a single example:public class Singledemo { private static singledemo s = null; Private Singledemo () {} public static Singledemo getinstance () { if (s = = null) { s = new Singledemo (); }
1. Multiple threads Repeat a result as follows: It's sold out and the warehouse is full.public class Productandconsumer {public static void main (string[] args) {Clerk Clerk = new Clerk (); Product Product = new product (clerk); Consumer Consumer =
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
Wait and notifyWait and notify can implement communication between threads, and when one thread executes a condition that does not meet the criteria, it can call the wait method to put the thread into a waiting state, and when another thread
1. Countdownlatch of SynchronizerThe name of the class is translated in Chinese as: the countdown latch (the countdown latch). When manipulating threads, sometimes we want this thread to wait until a certain number of events have occurred. To handle
1. Threads and processesThere are many examples of processes and threads, because it is a learning note, that is, I feel very good understanding, is that we use the QQ every day, But we run the QQ.exe program, the process begins, we can open the
Synchronized1. Multi-threaded execution of the same object synchronized function, thread synchronization is correct;The instance code is as follows:public class Test1 implements runnable{Defining the same object Static TEST2 action; public
Package test;
Import java.util.LinkedList;
public class Test {public static void main (string[] args) {r r = new R ();
P p1 = new P (r,10);
P p2 = new P (r,20);
P p3 = new P (r,30);
P P4 = new P (r,40);
P P5 = new P (r,50);
c C1 =
has been engaged for a long time, the producer and consumer model strengthened version (multi-person production multi-person consumption).The previous code format is no longer a slot (try to improve later)The output is an infinite loopImport
The most comprehensive Java multithreaded usage resolution, if you do not have in-depth research on Java multithreaded mechanism, this article can help you to understand more thoroughly Java multithreading principle and use method.
1. Creating
Recently, the data migration tool is almost completed. Today, the connection pool is changed to C3P0, and a problem is found, A deadlock occurs when C3P0 of multiple data sources is configured to obtain connections of different data sources at the
1. inherit the Thread class and implement the run Method
class TestThread{public static void main(String[] args){Thread1 t1=new Thread1();t1.start();int
Step by step _ Android development course [10] _ Thread learning, _ android_thread
Focus on technology, enjoy life! -- QQ: 804212028. Link: http://blog.csdn.net/y18334702058/article/details/44624305
Topic: Thread Learning-When a program is
I. Overview 1, the way of realizationIn Java for a multithreaded implementation must have a thread of the main class, and the main class of this thread is often required to operate some resources, but for the main class of multi-threaded
1. Multiple threads operate the same resource, but the action action is different, so there is a security issueFor example:public class Test {public static void main (string[] args) {Resource r = new Resource (); Input in = new input (r);
Recently reviewed the thread, found running consumer and producer code parts, there will always be first consumption after production.
The source code is as follows:
public class Producerconsumer {public static void main (string[] args) {syncstack
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.