Better use of Java thread pool

Introduction This article combines the JUC package provided by Doug Lea in JDK1.5 to understand the use of thread pools from the setting of thread pool size parameters, the creation of work threads, the recycling of idle threads, the use of blocking queues, task rejection strategies, thread pool Hook and other aspects, which involves some details including the choice of different parameters, different queues, different rejection strategies, the resulting The details include the different parameters, the different queues, the choice of different rejection strategies, the resulting impact and behavior, and for better use of the thread pool.

Synchronized keywords in java concurrency

Introduction In a multi-threaded environment, we often encounter resource competition, such as multiple threads going to modify the same shared variable at the same time, it is necessary to perform some processing of the resource access method to ensure that only one thread accesses it at the same time. Java provides the synchronized keyword to facilitate us to achieve the above operation. Why synchronized Let’s take an example where we create a class that provides a setSum method.

Difference between wait and sleep in java

Introduction In this post, we will discuss the difference between wait() and sleep() methods in java. And discuss how to use these two methods. Difference between wait and sleep wait() is a native method defined in Object. public final native void wait(long timeout) throws InterruptedException; So every instance of the class can call this method. wait() can only be called in a synchronized block. It will release the lock put on the object when it is synchronized.