Skip to content

Instantly share code, notes, and snippets.

public class WindowedInvoker<T, R> {
private final Semaphore semaphore = new Semaphore(windowSize);
private class ReleasingCallback<R> implements Consumer<R> {
private final Consumer<R> delegate;
@Override
public void accept(R result) {
semaphore.release();
delegate.accept(t);
public class BatchingAggregator<T> {
private final int maxBatchSize;
private final InterruptableConsumer<T> consumer;
private final BlockingQueue<T> queue = new LinkedBlockingDeque<>(maxQueueSize);
private final Thread thread = new Thread(this::process);
{
this.thread.start();
}
@mmimica
mmimica / dp2.java
Created April 5, 2018 12:18
cached data provider
interface DataProvider<I, R> {
T calculate(I input);
}
@RequiredArgsConstructor
public class DataProviderCached<I, R> implements DataProvider<I, R> {
private final DataProvider delegate;
private final Map<I, R> cache = new ConcurrentHashMap<>();
@Override
@mmimica
mmimica / dp.java
Created April 4, 2018 15:44
interview sample
@Data
class Result {
// ...
}
@Data
class Input {
// ...
}
@mmimica
mmimica / maven surefire output
Created January 23, 2018 23:06
mvn -X test
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T09:58:13+02:00)
Maven home: /opt/apache-maven-3.5.2
Java version: 9.0.4, vendor: Oracle Corporation
Java home: /opt/jdk-9.0.4
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.13.0-26-generic", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building junit-listener-test 1.0.0-SNAPSHOT
$ cat /proc/cpuinfo | grep "model name" | uniq -c
8 model name : Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
$ LD_PRELOAD=/home/mmimica/Downloads/zlib-1.2.8/libz-ipp.so.1.2.8 java -jar target/benchmarks.jar
...
Benchmark (level) Mode Cnt Score Error Units
ZipBenchmark.systemZlib 1 thrpt 5 48.007 ± 1.441 ops/s
ZipBenchmark.systemZlib 3 thrpt 5 48.393 ± 1.966 ops/s
ZipBenchmark.systemZlib 6 thrpt 5 19.767 ± 0.830 ops/s
ZipBenchmark.systemZlib 9 thrpt 5 14.099 ± 0.412 ops/s
package com.mmimica;
import java.io.*;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
package com.mmimica;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.openjdk.jmh.annotations.*;
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)