This file contains 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
/** | |
* Executor which useful for unit testing | |
*/ | |
public class CurrentThreadExecutor implements ExecutorService { | |
@Override | |
public void execute(Runnable command) { | |
command.run(); | |
} |
This file contains 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.lang.ref.WeakReference; | |
import java.util.concurrent.*; | |
import java.util.function.Consumer; | |
public class SchedulerLeakProtector { | |
public static <T> ScheduledFuture<?> scheduleAtFixedRate(ScheduledExecutorService scheduler, T target, Consumer<T> consumer, long initialDelay, long period, TimeUnit timeUnit) { | |
CompletableFuture<ScheduledFuture<?>> scheduledFutureFuture = new CompletableFuture<>(); | |
LeakProtectedRunnable<T> runnable = new LeakProtectedRunnable<>(target, consumer, scheduledFutureFuture); | |
ScheduledFuture<?> scheduledFuture = scheduler.scheduleAtFixedRate(runnable, initialDelay, period, timeUnit); |
This file contains 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
<dependency> | |
<groupId>org.gridkit.lab</groupId> | |
<artifactId>nanocloud</artifactId> | |
<version>0.8.8</version> | |
</dependency> | |
<dependency> | |
<groupId>org.gridkit.lab</groupId> | |
<artifactId>telecontrol-ssh</artifactId> | |
<version>0.8.8</version> | |
</dependency> |
This file contains 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; |
This file contains 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 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 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 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 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 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> { |
OlderNewer