Assigning a reference to itself in Java has no effect, right? – WRONG!

Tags: , , ,

You see this piece of code in your beloved code base…. referenceToSomethingImportant = referenceToSomethingImportant; You immediately delete it since assigning a variable to itself will never do any thing. Of course the compiler or the JIT machinery is always going to optimize it away anyway. Right? Wrong. Oh yes, there might be another thread you […]

Continue reading » 2 Comments

ConcurrentHashSet in Java from ConcurrentHashMap

Tags: ,

Problem While you do have a ConcurrentHashMap class in Java, there is no ConcurrentHashSet. Solution You can easily get a ConcurrentHashSet with the following code – Collections.newSetFromMap(new ConcurrentHashMap<Object,Boolean>()) Notes A Set lends itself to implementation via a Map if you think about it. So can actually just use a Map. But that may not fit […]

Continue reading » 1 Comment

Blocked thread with Read Write Lock due to writer starvation

Tags: , , ,

Here is an interesting and simple example of how you can end up with a locked thread in your application and what you can do to avoid it. Task A – Starts at t = 0. Takes a read lock. Runs for 3 seconds. Scheduled to run every 5 seconds. Task B – Starts at […]

Continue reading » 1 Comment

Fix ConcurrentModificationException on ArrayList with CopyOnWriteArrayList

Tags: , , ,

You have a List in your application that is traversed or iterated over very frequently but is modified very rarely. Like a ‘Top 10’ kind of list on your home page which is served for every hit to the home page (think hundreds of hits per second) and is updated by an hourly Quartz job. […]

Continue reading » 2 Comments

Erlang – A very basic introduction

Tags: , , , ,

I saw a bunch of presentations on Erlang recently. The talks by Joe Armstrong, the inventor of the language, are quite lightweight on code content and the actual language itself and are interspersed with humor. He mostly talks about the central problems which Erlang is designed to solve – scalable, fault tolerant, shared nothing architecture […]

Continue reading » Comments Off on Erlang – A very basic introduction