Home » Author Archives: Peter Lawrey (page 4)

Author Archives: Peter Lawrey

Adding @atomic operations to Java

java-logo

Overview How might atomic operations work in Java, and is there a current alternative in OpenJDK/Hotspot it could translate to. Feedback In my previous article on Making operations on volatile fields atomic. it was pointed out a few times that “fixing” previous behaviour is unlikely to go ahead regardless of good intentions.   An alternative to this is to add an @atomic annotation. ...

Read More »

MineCraft and off heap memory

java-logo

Overview MineCraft is a really good example of when off heap memory can really help. The key requirements are: The bulk of the retained data is a simple data structure (in minecraft’s case its lots of byte[]) The usage of off heap memory can be hidden in abstraction.     The test I used the following test for starting minecraft ...

Read More »

Making Unsafe safer

java-logo

Overview If you use Unsafe directly, you risk crashing the JVM.  This happens when you access a page of memory which hasn’t been mapped and the result on Unix is a SIGSEG (if you access page 0) or SIGBUS (if you access another page which is not mapped). Using MethodHandles Wrapping Unsafe method with a MethodHandle is a possible solution. ...

Read More »

SharedHashMap vs Redis

redis-logo

Overview This is a comparison between OpenHFT’s SharedHashMap and a popular key-value store Redis. Any vendor will tell you how great their product is, so I will start by outlining why you wouldn’t use SharedHashMap, before I tell you why it is a “must have” for performant applications.       Why you would use Redis? Redis is a more ...

Read More »

Chronicle and low latency in Java

java-logo

Overview I was watching this excellent presentation by Rolan Kuhn of Typesafe on Introducing Reactive Streams At first glance it appears that it has some similar goals to Chronicle, but as you dig into the details it was clear to me that there was a few key assumptions which were fundamentally different.   Key assumptions The key assumptions  in the design of ...

Read More »

Common Java Myths

java-logo

These are questions which are likely to be too advanced to ask in any interview as they may just put candidates off.  Never the less, they may be work practising in your own time.                 Myth 1) System.exit(0) prevents finally being called Why does this code System.setSecurityManager(new SecurityManager() { @Override public void checkExit(int ...

Read More »

Java arrays, Wat!?

java-logo

There is a few things you can do with arrays which are surprising.                     Is it an array or not? Serializable array = new Serializable[9]; Is array an array or a scalar? Well its a scalar which points to an array. Just like  Object o = new Object[9]; You can assign ...

Read More »

Common gotchas in Java

java-logo

Overview Java is a minimalist language with deliberately less features than other languages, never the less it has edge cases which strange effects, and even some common cases with surprising effects to trip up the unwary. If you are used to reading another language you can easily read Java the wrong way leaving to confusion. Variables are only references or ...

Read More »

Hardware Transactional Memory in Java, or why synchronized will be cool again

java-logo

Overview Hardware Transaction Memory has the potential to allow multiple threads to speculatively access the same data structure at the same time and let the cache coherence protocol determine if a conflict occurred.  HTM aims to give you the scalability of fine grain locking, the simplicity of course grain locking, and performance close to no locking at all.  If supported ...

Read More »

sun.misc.Unsafe and off heap memory

java-logo

The class sun.misc.Unsafe allows you to many of the things you shouldn’t be able to do in Java, but are still useful in very specific cases. It is to be avoided 99% of the time, however there are rare occasions where this is the only solution which makes sense. This post considers how it has been using in OpenHFT and ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Advanced Java Guide
  • Java Design Patterns
  • JMeter Tutorial
  • Java 8 Features Tutorial
  • JUnit Tutorial
  • JSF Programming Cookbook
  • Java Concurrency Essentials