Showing posts with label Concurrency. Show all posts
Showing posts with label Concurrency. Show all posts

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.

Thursday, 30 December 2010

Seven Languages in Seven, er, Months

A week or so before Christmas, an intriguing book popped up on my recommended list at Amazon. This was Bruce Tate's Seven (Computer) Languages in Seven Weeks (ISBN 193435659X). The idea behind the book is to teach certain programming concepts through the medium of the languages that embody them the best. Object orientation and dynamic typing are taught using Ruby, a language in which Tate does most of his work; prototyping, which I'm not very familiar with, is demonstrated through Io, a language I'd never even heard of before; functional programming is through Haskell; concurrency (using actors not threads!?!) through Erlang, and so on. There is also a chapter on Scala, which I've had some experience of, so I'm intrigued to see what he has to say about that.