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
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 { |
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
if (!tasks.offer(task)) { | |
throw new RejectedExecutionException("back-pressured?"); | |
} | |
if (!running) { | |
lock.lock(); | |
try { | |
condition.signal(); | |
} finally { | |
lock.unlock(); | |
} |
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
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 { |
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 interface WritableBuffer | |
{ | |
void put(CharSequence chars); | |
} | |
/** | |
* Writable Buffer implementation based on a Netty ByteBuf | |
*/ | |
public class AmqpWritableBuffer implements WritableBuffer { |
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 static void main(String[] args) { | |
//WARMING UP a() | |
//.... | |
for (int i = 0; i < Integer.MAX_VALUE; i++) { | |
a(); | |
} | |
} | |
private static void a() { | |
b(); |
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 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; |
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
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; |
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
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)); | |
} |
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 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 |
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 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(() -> { |
OlderNewer