CountDownLatch&Semaphore&CyclicBarrier&Executors of concurrent programming

1, Semaphore Semaphore definition Semaphore literally means semaphore. Its function is to control the number of threads accessing specific resources. The bottom layer depends on the State of AQS. It is a tool class commonly used in production. Common methods of Semaphore Construction method public Semaphore(int permits) public Semaphore(in ...

Added by ca87 on Wed, 02 Feb 2022 14:12:53 +0200

Chapter 3 - management of shared model

Chapter 3 - management of shared model (3) wait-notify Little story - why wait Because the conditions are not met, Xiaonan cannot continue the calculationBut if Xiaonan keeps occupying the lock, others will have to block all the time. The efficiency is too low So Lao Wang opened a single Lounge (calling the wait method) and asked Xiao Nan ...

Added by celsoendo on Wed, 02 Feb 2022 11:43:17 +0200

Memory overflow problem + singleton mode + custom blocking queue

ThreadLocal uses: 1.set: set the private variable to the thread 2.get: get ThreadLocal from thread 3.remove: remove ThreadLocal from the thread. 4.initialValue: initialization 5.withInitialValue: initialization (lambda expression) Usage scenario: 1. Solve thread safety problems 2. Realize thread level data transmission Disadvantages: 1. Data ...

Added by optik on Wed, 02 Feb 2022 04:13:52 +0200

Asynchronous and thread pool

1, Four ways to initialize threads Inherit Thread classImplement Runnable interfaceImplement Callable interface + FutureTask (you can get the returned results and handle exceptions)Thread pool Inherit the Thread class and implement the Runnable interface: the main process cannot obtain the operation result of the Thread.Implementation o ...

Added by byronwells on Tue, 01 Feb 2022 21:34:34 +0200

Java thread summary

Java thread summary (I) 1. Thread life cycle 1) Create (3 ways) a. Inherit Thread class public class ThreadDemo1 extends Thread{ @Override public void run() { for(int i=0;i<10;i++) { System.out.println(i); } } } b. Implement Runnable interface public class ThreadDemo2 implements Runnable { @Override public void ru ...

Added by nickman013 on Tue, 01 Feb 2022 12:51:33 +0200

Chapter 3 - management of shared model

Chapter 3 - management of shared model (1) Contents of this chapter Sharing problemsynchronizedThread safety analysisMonitorwait/notifyThread state transitionActivityLock Problems caused by sharing Little story Lao Wang (operating system) has a powerful abacus (CPU). Now he wants to rent it and earn some extra money Xiao Nan and Xia ...

Added by morphboy23 on Tue, 01 Feb 2022 10:02:58 +0200

Java Exceptions and Multithreading

abnormal Concepts and Systems of Exceptions Classification of Exceptions public static void main(String[] args) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = simpleDateFormat.parse("202106-01"); //ParseException System.out.println(date); } public static void main ...

Added by cturner on Tue, 01 Feb 2022 08:37:33 +0200

Basic explanation of Python crawler: the use of threading module

Python crawler, data analysis, website development and other case tutorial videos can be viewed online for free https://space.bilibili.com/523606542 Python learning exchange group: 1039649593 Use of threading module python's thread module is the underlying module, and python's threading module wraps thread, which can be used more conve ...

Added by johnmess on Tue, 01 Feb 2022 05:22:47 +0200

Redis Chapter 4 distributed lock principle + native implementation code

Redis Chapter 4 implementation of distribution lock and Lua script + native code implementation In the previous article, redistribute was introduced. The application of redistributed in distributed locks is very simple and convenient, but redistribute itself is a encapsulated framework. In this section, we explore the implementation of Redis's ...

Added by bothwell on Mon, 31 Jan 2022 21:44:49 +0200

Multithreading Foundation

@Yixian loves potatoes 1. Process Each process has its own independent memory space and system resources(running program) cpu time slice: refers to system resources and memory space 2. Thread It is an execution line in the process Each thread performs a taskThread is the basic scheduling unit of CPU 3. Relationship between process and thr ...

Added by x_filed2k on Mon, 31 Jan 2022 15:03:07 +0200