Implementing an AtomicInteger

What is AtomicInteger As the name suggests, AtomicInteger is an Integer with atomic operations. The difference between AtomicInteger and a regular Integer is that AtomicInteger uses a CAS method to make Integer’s increment and other operations atomic. Knowledge needed before implementation First, let’s look at the increment operation of AtomicInteger: 1 2 3 4 5 6 7 8 public final int incrementAndGet() { for (;;) { int current = get();

What is Minor GC/Major GC

What is Minor GC/Major GC First, let’s popularize the classic heap layout of JVM: For the classic JVM heap layout, there are two clear areas, the first is the Young area, which generally stores young objects or objects that have just been created. The second is the Old area, also known as the old generation, which generally stores longer-lived objects or objects promoted from the young area. For the young area, we have three areas, one is the Eden area, and the other two are Survivor areas of equal size.

Where is the GC root?

What is GC Root First of all, we know the marking algorithm, the JVM’s marking algorithm can be understood as a reachability algorithm, so all reachability algorithms will have a starting point, and this starting point is the GC Root. That is, it is necessary to find all living objects through the GC Root, and then all the remaining unmarked objects are the objects to be recycled. Characteristics of GC Root Objects that are alive at the current moment!

Design and Implementation of the Leaky Bucket Algorithm

What is the Leaky Bucket Algorithm? As the name suggests, the Leaky Bucket algorithm uses a leaky bucket to limit traffic. Because there is a hole at the bottom of the bucket, it will leak water at regular intervals, and we can imagine the traffic as water falling into the bucket from above. This leads to two situations. If the speed at which traffic is injected into the bucket is

Pointing to offer

No2 Singleton Pattern 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class No2TwiceCheckSingleton { private volatile static No2TwiceCheckSingleton instance = null; private static final Object sybObj = new Object(); // 一定记住要私有化构造器,不然人家还是能够创建 private No2TwiceCheckSingleton() { } static No2TwiceCheckSingleton