Ballmerpeak devblog

Software development, related stuff and others

Threads: Why you should hate and love them 2: LazyHashLock

July 26, 2015 — Richárd Thier

Java has many interesting built-in and library tools for locking, synchronization and parallel/concurrent programming in general, but you can always find situations when the built in toolset is not enough or more often: not convenient enough. In most situations, the problem can be solved in some usual way, but you feel it is not the best way to do that and I think some of us create a generic solution in those times. This is how design patterns, practices and libraries appear and because I have found an interesting kind of lock that can be handy in many situations I have decided to share some of my code: enjoy my little solution that I call "LazyHashLock".

Read more...

Tags: java, lazy, hash, lock, concurrency, LazyHashLock, parallel, thread, synchronization, case study, striping, splitting, pool, shared

Threads: Why you should hate and love them 1

July 12, 2015 — Richárd Thier

I think most software developers already (think that they) know much about threads. People know the problem of the dining philosophers, they heard how hard is to ensure correctness and know about tales of various threading related catastrophes. Despite this, however I still feel that there are many (not even poor) practical-only developers out there who still underestimate the various problems threading issues can introduce: The kind of people who always argue (sometimes with understandable arguments) that "patterns and rules are good, but in practice you can break them 'for the real life'" or "in theory there are these or those problems, but 'reality is different' and you can live without this or that rule if the software is written according to the business demands (and you should focus that)" also tend to think about threading issues with the same mindset... This however just doesn't work in the case of concurrency - if you break it, it is utterly broken in many ways you are not aware of, and what is worse is that these problems cannot be found out by testing!

Because I want to spread some of the wisdom on this hard topic, I've choosen to write down some of my suggestions and some examples that I have found in real-life. I hope it makes sense and helps the readers.

As an addendum, I have chosen to use a nice little diagramming tool that I have found while lurking around the internet to make my illustrations readable from a console. I think this is something that I will try to do for the future too, as I want this blog to be enjoyable from elinks too (of course there will be exceptions I think, but it is better to minimize them in my opinion)

Read more...

Tags: threads, concurrency, java, OSGi, development, lock ordering, deadlock, dump analysis, asciiflow, bug, analysis