Wednesday 12 March 2014

Tuesday - Java Concurrent Animated

I thought I take a trip into town this evening to see a presentation at Skills Matter by Victor Grazi (complete with "Brooklyn accent") concerning Java concurrency.


Concurrency is always a difficult subject, but not so much the thing itself as what happens when concurrent processes try to access the same resources at the same time. Normally, in Java, this is done via the "synchronized" command. You designate a block of code and wrapper it in a synchronized block:

synchronized(this) {
    Counter.count++;
    System.out.print(Counter.count + "  ");
}

or declare a function to be synchronized:

public synchronized void assign(int i) {
    val = i;
}

However, if one thread gets to the block first, it locks out the any other threads trying to do the same. There's nothing that the others can do about it other than wait.

Victor's presentation was regarding what was available in the Java API, such as Locks, Semaphores, to get around this or avoid it altogether, as well as exploring other aspects of the API such as Thread Pooling.

What made this presentation a little different was the animation of the threads, which were doing little animated circuits to illustrate his points. The source can be found on SourceForge.


As you can see, it looks cute. Plus is does show you the various options available to the Java programmer other than just the ubiquitous "synchronized".

Victor gave a very good presentation of a difficult, but important, subject.

No comments:

Post a Comment