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.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.function.Function; | |
import static java.util.Objects.requireNonNull; |
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
public class SProcMapParserExample { | |
private static InputStream stream = SProcMapParserExample.class.getResourceAsStream("/some_dump_of_proc_maps.txt"); | |
public static class AllStat { | |
public static void main(String[] args) throws IOException { | |
SProcMap map = ProcSMapsParser.parse(stream); | |
List<ProcSMapItem> items = map.getItems(); | |
Collections.sort(items, Comparator.comparingLong(item -> item.getAttributes().get("Rss"))); | |
Collections.reverse(items); |
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.util.concurrent.atomic.AtomicReference; | |
/** | |
* An example of classic Michael-Scott queue | |
* | |
* @param <T> | |
*/ | |
public class MSQueue<T> { | |
private final class Node<T> { |
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.util.ArrayList; | |
import java.util.List; | |
import java.util.Queue; | |
import java.util.concurrent.ConcurrentLinkedQueue; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.concurrent.atomic.AtomicReferenceArray; | |
public class AutoExpandingConcurrentArray<T> { |
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
public class SomeWrapper { | |
private final long nativeAddress; | |
public SomeWrapper(long nativeAddress) { | |
this.nativeAddress = nativeAddress; | |
} | |
protected void finalize() throws Throwable { | |
deleteNativeObject0(); |
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 com.ringcentral.tread_creation_profiler; | |
import net.bytebuddy.agent.ByteBuddyAgent; | |
import net.bytebuddy.agent.builder.AgentBuilder; | |
import net.bytebuddy.asm.Advice; | |
import net.bytebuddy.description.type.TypeDescription; | |
import net.bytebuddy.dynamic.ClassFileLocator; | |
import net.bytebuddy.dynamic.DynamicType; | |
import net.bytebuddy.dynamic.loading.ClassInjector; | |
import net.bytebuddy.matcher.ElementMatchers; |
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.concurrent.locks.StampedLock; | |
import java.util.function.Supplier; | |
public class CachingSupplier<T> implements Supplier<T> { | |
private final Supplier<T> targetSupplier; | |
private final long cachingDurationNanos; | |
private final StampedLock stampedLock = new StampedLock(); |
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
public class GracefullyStoppingScheduledFuture { | |
public static GracefullyStoppingScheduledFuture cheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit, ScheduledExecutorService scheduler) { | |
CancellableCommand cancellableCommand = new CancellableCommand(command); | |
ScheduledFuture future = scheduler.scheduleAtFixedRate(cancellableCommand, initialDelay, period, unit); | |
return new GracefullyStoppingScheduledFuture(future, cancellableCommand); | |
} | |
private GracefullyStoppingScheduledFuture(ScheduledFuture targetFuture, CancellableCommand command) { | |
this.targetFuture = targetFuture; |
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 com.netflix.hystrix.HystrixCommand; | |
import com.netflix.hystrix.HystrixCommandGroupKey; | |
import com.netflix.hystrix.HystrixCommandProperties; | |
public class HystrixRunInCallerThread { | |
static HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter() | |
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE) | |
.withExecutionIsolationSemaphoreMaxConcurrentRequests(10) |
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.util.LinkedList; | |
/** | |
* The naive solution for rate limiter which potentially leads to crash JVM with out of memory error. | |
*/ | |
public class NaiveRateLimiter { | |
private long availableTokens; | |
private final long periodMillis; |
NewerOlder