Posts Tagged ‘Concurrency’

Java Concurrency – Part 7 : Executors and thread pools

Let’s start with a new post in the Java concurrency series.
This time we’ll learn how to start cleanly new threads and to manage thread pools. In Java, if you have a Runnable like this :

Runnable runnable = new Runnable(){
public void run(){
System.out.println("Run");
}
}

You can easily run it in a new thread :
new Thread(runnable).start();
This is …

Java Concurrency – Part 6 : Atomic Variables

When a data (typically a variable) can be accessed by several threads, you must synchronize the access to the data to ensure visibility and correctness.
By example, if you have a simple counter (yes, once again) :

public class Counter {
private int value;
 
public int getValue(){
return value;

Java Concurrency – Part 5 : Monitors (Locks and Conditions)

After seeing how to synchronize code using semaphores, we’ll see how to do that using monitors.
Monitors are an other mechanism of concurrent programming. It’s a higher level mechanism than semaphores and also more powerful. A monitor is an instance of a class that can be used safely by several threads. All the methods of a monitor are executed with mutual exclusion. So at most …

Java Synchronization (Mutual Exclusion) Benchmark

I’ve created another benchmark. This time, I’ve benchmarked the different ways of synchronizing a little code using mutual exclusion on this code.
The code to protect will be very simple. It’s a simple counter :

//Init
int counter = 0;
 
//Critical section
counter++;

The critical section, if not protected with synchronization system, will not function properly due to possible interleavings (read the article on synchronization if you don’t know …

Java Concurrency – Part 4 : Semaphores

We continue with the Java Concurrency thema with the semaphores. Semaphores is also a way to synchronize threads.
Semaphores are a really simple concept, invented by the famous Dutch computer scientist Edsger Dijkstra. Basically a semaphore is a counter (integer) that allows a thread to get into a critical region if the value of the counter is greater than 0. If it’s the case, the …

Java Concurrency – Part 3 : Synchronization with intrinsic locks

After learning how to create threads and manipulate them, it’s time to go to most important things : synchronization.
Synchronization is a way to make some code thread safe. A code that can be accessed by multiple threads must be made thread safe. Thread Safe describe some code that can be called from multiple threads without corrupting the state of the object or simply doing …

Java Concurrency in Practice – Book Review

Hi,
I used my holidays to concentrate myself on the reading of my last book : Java Concurrency in Practice of Brian Goetz (with Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes and Doug Lea).
This book is, in my point of view, the reference for the development of concurrency programs in Java.
Reading this book, you will learn that concurrency is everywhere when programming in Java …

JR Virtual machines

Until now, we’ve always had concurrent program working in one virtual machines, but JR provides ways to declare several virtual machines on several different physical machines. A JR Virtual Machine contains a Java Virtual Machine and a layer for the JR language. Once you created some virtual machines, you can specify where an object will be created with a variant of the new operator. …

Rendezvous, concurrency method, in JR

In this post, we’ll see a new feature of JR : the rendezvous.
Like asynchronous message passing, this synchronization method involves two processes : a caller and a receiver. But this time, the invocation is synchronous, the caller delays until the operation completes. The rendezvous does not create a new thread to the receiver. The receiver must invoke an input statement (the implementation of rendezvous) …

Asynchronous Message Passing in JR

We’ve now covered the basic synchronization systems (semaphore, monitors) and we know how to declare operations and capabilities . It’s time to go to an other form of synchronization : Message Passing. In this post, we’ll focus in Asynchronous Message Passing, we’ll cover later, the synchronous message passing system with RendezVous.
When we use message passing, the threads doesn’t share datas anymore, they share channels. …