This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import java.lang.management.ManagementFactory; | |
import java.lang.management.OperatingSystemMXBean; | |
import java.time.Instant; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.concurrent.ArrayBlockingQueue; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.ForkJoinPool; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from Jon Schneider | |
public class GaugeUpdateTrick { | |
public static void main(String[] args) { | |
AtomicLong lastCalculatedTime = new AtomicLong(0); | |
AtomicLong gaugeValue = new AtomicLong(0); | |
Gauge.builder("expensive", () -> { | |
long curr = System.nanoTime(); | |
return gaugeValue.updateAndGet(old -> | |
lastCalculatedTime.updateAndGet(ts -> curr - ts > 10_000 ? curr : ts) == curr ? 0L /* new */ : old); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.Duration; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.*; | |
import java.util.concurrent.atomic.AtomicInteger; | |
public class ForkJoinPoolDemo { | |
private static final int SUBMISSIONS = 10; | |
private static final int FORKS = 24; | |
private static final int PARALLELISM = 5; |
OlderNewer