Use of wait/notify and J.U.C Condition in synchronized thread communication and source code analysis

I remember there was a classic interview question: how to output from 1 to 100 in sequence with multiple threads? The last chapter talked about the use and principle analysis of locks in Java. The above interview questions should be handy This chapter mainly talks about the realization of production and consumption queue and Condition source c ...

Posted on Mon, 06 Dec 2021 23:08:14 -0500 by GoodWill

Comparison of ReentrantLock, ReentrantReadWriteLock, synchronized and Lock

1, ReentrantLock   after introducing AQS in the previous article, let's introduce the application of AQS: ReentrantLock. ReentrantLock is mainly implemented by CAS+AQS queue and supports fair lock and unfair lock.   example of ReentrantLock: private Lock lock = new ReentrantLock(); public void test(){ lock.lock(); ...

Posted on Sun, 24 Oct 2021 14:51:25 -0400 by Sir Mildred Pierce

MySQL lock (read lock, write lock, table lock, row lock)

MySQL lock mechanism definition Definition: a lock is a mechanism by which a computer coordinates multiple processes or threads to access a resource concurrently Classification of locks Classification of locks: 1. From the type of data operation (read / write) Read lock (shared lock): for the same data, multiple read operations can be per ...

Posted on Sun, 24 Oct 2021 06:35:07 -0400 by Adastra

Python - multithreading Parallel / Multiprocessing Demo

1, Introduction Multithreading and thread pool are commonly used in Java development to improve program running efficiency and machine utilization. Python multithreading uses Parallel class and Multiprocessing class. In addition, there are  _ Thread, threading and many other thread related classes can cooperate with os, sys, subprocess an ...

Posted on Wed, 20 Oct 2021 22:43:00 -0400 by peanutbutter

Introduction to concurrency Basics

1, Fair lock and unfair lock Rendering of unfair lock: it can be seen that in the case of multiple threads, one thread will monopolize and other threads will starve to death. Because the process of thread switching is omitted, the efficiency is relatively high public void test1(){ test test = new test(); new Thread(()-> ...

Posted on Mon, 18 Oct 2021 13:58:38 -0400 by dotBz

Synchronized underlying principle

java object and object header Locks in java Monitor heavyweight lock Monitor is translated as monitor or tube pass Synchronized is implemented through a called Monitor lock inside the object. However, the essence of Monitor lock depends on the Mutex Lock of the underlying operating system. The operating system realizes the switching b ...

Posted on Sun, 03 Oct 2021 13:47:58 -0400 by nonexistentera

The difference between Lock and synchronized

Of course, the implementation of synchronization adopts locks. The two basic tools for using locks in java are synchronized and Lock. // Unsynchronized method public void test() {} // Synchronization method pubilc synchronized void test() {} synchronized It can also be used in a code block. Look public void test() { synchronized(obj) { ...

Posted on Fri, 24 Sep 2021 03:16:52 -0400 by Nik