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

How to split a file, process the pieces in multiple threads and combine results using a shell script

Tags: , , , , , ,

Say you are in a situation where you have a file with a huge number of records to be processed and the processing of one record does not need data from the processing of previous records (ie. a perfectly paralellizable situation), what can you do to speed up things? Well, here’s what I did when […]

Continue reading » 4 Comments

Java Synchronization Benchmark

Tags: , , , , , , , , ,

Here is a very simple and straightforward benchmark to demonstrate how synchronization in Java can affect speed of execution to different extents in Java 1.4 and Java 6. In the attached image (click above for full size), you can see that for Java 1.4 the synchronized method needs over 700% more time to do its […]

Continue reading » 7 Comments