Skip to content

Instantly share code, notes, and snippets.

View franz1981's full-sized avatar
🏠
Working from home

Francesco Nigro franz1981

🏠
Working from home
View GitHub Profile
private final Queue<Runnable> tasks = new MpscArrayQueue<>(64);
private final ReentrantLock lock = new ReentrantLock();
private final Condition condition = lock.newCondition();
private volatile boolean running = true;
private final Thread executorThread = new Thread(() -> {
do {
running = true;
Runnable task;
while ((task = tasks.poll()) != null) {
try {
if (!tasks.offer(task)) {
throw new RejectedExecutionException("back-pressured?");
}
if (!running) {
lock.lock();
try {
condition.signal();
} finally {
lock.unlock();
}
private final Queue<Runnable> tasks = new MpscArrayQueue<>(64);
private final ReentrantLock lock = new ReentrantLock();
private final Condition condition = lock.newCondition();
private volatile boolean running = true;
private final Thread executorThread = new Thread(() -> {
do {
running = true;
Runnable task;
while ((task = tasks.poll()) != null) {
try {
public interface WritableBuffer
{
void put(CharSequence chars);
}
/**
* Writable Buffer implementation based on a Netty ByteBuf
*/
public class AmqpWritableBuffer implements WritableBuffer {
public static void main(String[] args) {
//WARMING UP a()
//....
for (int i = 0; i < Integer.MAX_VALUE; i++) {
a();
}
}
private static void a() {
b();
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.profile.SafepointsProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;
default int write(Supplier<?> msgs, int limit, Predicate<? super ChannelOutboundInvoker> stopCondition, Supplier<? extends ChannelPromise> promises, Consumer<? super ChannelFuture> futures) {
for (int i = 0; i < limit; i++) {
final boolean stop = stopCondition.test(this);
if (stop) {
return i;
}
final Object msg = msgs.get();
assert msg != null;
final ChannelPromise promise = promises.get();
assert promise != null;
private static long minusOneIfNotLongMax(long value) {
final long valueMinusOne = value - 1;
final long diffFromValue = value - Long.MAX_VALUE;
final long tmp = (diffFromValue - 1) >> 63;
final long mask = ((diffFromValue >> 63) ^ tmp) & tmp;
return (value & mask) | (valueMinusOne & (~mask));
}
public static void main(String[] args) {
final int parallelism = 8;
final ExecutorService executor = Executors.newFixedThreadPool(parallelism);
final CyclicBarrier started = new CyclicBarrier(parallelism);
final Callable<Long> task = () -> {
started.await();
final Thread current = Thread.currentThread();
long executions = 0;
while (!current.isInterrupted()) {
//quello che deve fare sul DM
public static void main(String[] args) {
final ExecutorService executorService = Executors.newFixedThreadPool(2);
final int tests = 5;
final int iterations = 10_000_000;
final int length = 64;
final AtomicBoolean releaser = new AtomicBoolean();
final double[] values = new double[length];
final AtomicBoolean finished = new AtomicBoolean(false);
Arrays.fill(values, Double.MAX_VALUE);
executorService.submit(() -> {