Home » Tag Archives: Concurrency (page 5)

Tag Archives: Concurrency

Agrona’s Threadsafe Offheap Buffers

This blog post continues my ongoing series on the Agrona library by explaining how we offer easy access to offheap memory for threadsafe operations. I should probably caveat before we move on that this is a fairly advanced topic and I don’t attempt to explain concepts such as memory barriers – merely outline the features of the API. The deficiencies ...

Read More »

A Case Study in Analysing Latency: Lock vs Synchronized

In particular in this post we will discuss: Garbage created by java.concurrent.Lock Comparing Lock to synchronized How to measure latency programatically The impact of contention on Lock and synchronized The impact of co-ordinated omission on latency tests Back to one of my favourite topics garbage creation / allocation. See my previous posts (e.g. First rule of performance optimisation and Revisiting the First Rule of ...

Read More »

Dealing with Interruptions

I was just watching the VJUG interview with Heinz Kabutz which inspired me to write a post about Interruptions. By the way I would recommend subscribing to the VJUG YouTube channel – very informative indeed. Heinz is always good value and it’s difficult to watch any of his presentations without learning a lot. He raised the topic of how to deal ...

Read More »

Farewell to Asynchronous Code


Quasar is a library that adds true lightweight threads (fibers) to the JVM. These are very cheap and very fast – in fact, fibers behave just like Erlang processes or Go goroutines – and allow you to write simple blocking code while enjoying the same performance benefits of complex asynchronous code. In this post we’ll learn how to transform any asynchronous, ...

Read More »

Shooting yourself in the foot with Random number generators

This is not going to be one of the posts explaining how a random number generator is not so random after all. So those of you expecting a guideline for how to hack a slot machine, move along, nothing to see here. Instead, it is a post about one of the not-so-uncommon lock contention issues, hidden inside random number generators ...

Read More »

CompletableFuture can’t be interrupted

I wrote a lot about InterruptedException and interrupting threads already. In short if you call Future.cancel() not inly given Future will terminate pending get(), but also it will try to interrupt underlying thread. This is a pretty important feature that enables better thread pool utilization. I also wrote to always prefer CompletableFuture over standard Future. It turns out the more ...

Read More »

Java Concurrency Tutorial – Locking: Explicit locks

1. Introduction In many cases, using implicit locking is enough. Other times, we will need more complex functionalities. In such cases, java.util.concurrent.locks package provides us with lock objects. When it comes to memory synchronization, the internal mechanism of these locks is the same as with implicit locks. The difference is that explicit locks offer additional features. The main advantages or ...

Read More »

Java8 Multi-threading ForkJoinPool: Dealing with exceptions

One of the main motivations behind the introduction of Java8 lambdas was the ability to be able to use multicores as easily as possible (see Mastering Lambdas: Java Programming in a Multicore World).  By simply changing your code from collection.stream()... to collection.parallelStream()... you have instant multi-threading at your disposal which brings with it all the CPU power on your machine. ...

Read More »