Wednesday, February 27, 2019
Manage bitempotal data with BarbelHisto
Wednesday, January 30, 2019
Modern State Pattern using Enums and Functional Interfaces
It’s offen the case that the behaviour of an object should change depending on the objects state. Consider a ShoppingBasket
object. You can add articles to your basket as long the order isn’t submitted. But once it’s submitted you typically don’t want to be able to change that order anymore. So, there are two states in such a shopping basket object: READONLY
and UPDATEABLE
.
Tuesday, January 29, 2019
Passing multiple arguments into stream filter predicates
When I am working with java streams I am intensively using filters to find objects. I offen have the situation where I'd like to pass two arguments to the fiter function. Unfortunately the standard API does only accept a Predicate
but not BiPredicate
.
To solve this limitation I define all my predicates as methods in a class, say Predicates
. That predicate class takes a constant parameter.
Friday, May 4, 2012
Java 7: NIO.2 I/O operations on asynchronous channels are not atomic
AsynchronousFileChannel -> write()
does not garantee to write all bytes passed as parameter to the destination file. Instead it returns the number of bytes written as return parameters of the corresponding I/O operations and the client needs to deal with situations where the bytes written isn't equal to the remaining bytes in the passed ByteBuffer
. Java 7: Closing NIO.2 file channels without loosing data
Thursday, April 19, 2012
Threading stories: ThreadLocal in web applications
ThreadLocal
variables in our web applications. The reason was that they created classloader leaks and we coudn't undeploy our applications properly anymore. Classloader leaks happen when a GC root keeps referencing an application object after the application was undeployed. If an application object is still referenced after undeploy, then the whole class loader can't be garbage collected cause the considered object references your applications class file which in turn references the classloader. This will cause an OutOfMemoryError
after you've undeployed and redeployed a couple of times.Thursday, April 5, 2012
Java 7: NIO.2 File Channels on the test bench - Part 2 - Applying custom thread pools
Iocp
class that performs all the asynchronous I/O tasks in NIO.2 file channels is, by default, backed by a so called "cached" thread pool. That's a thread pool that creates new threads as needed, but will reuse previously constructed threads *when* they are available. Look at the code of the ThreadPool
class held by the Iocp
.Java 7: NIO.2 File Channels on the test bench - Part 1 - Introduction
AnsynchronousFileChannel
class. I am analyzing the new JDK 7 features in depth for a couple of weeks now and I have decided to number my posts consecutively. Just to make sure I don't get confused :-) Here is my 7th post about Java 7 (I admit that - by coincidence - this was also a little confusing). Using NIO.2 asynchronous file channels effectively is a wide topic. There are some things to consider here. I have decided to devide the stuff into four posts. In this first part I will introduce the involved concepts when you use asynchonous file channels. Since these file channels work asynchronously, it is interesting to look at their performance compared to conventional I/O. The second part deals with issues like memory and CPU consumption and explains how to use the new NIO.2 channels safely in a high performance scenario. You also need to understand how to close asynchronous channels without loosing data, that's part three. Finally, in part four, we'll take a look into concurrency. Thursday, February 2, 2012
Java 7: A complete invokedynamic example
invokedynamic
, a new bytecode instruction on the JVM for method invocation. The invokedynamic
instruction allows dynamic linkage between a call site and the receiver of the call. That means you can link the class that is performing a method call to the class (and method) that is receiving the call at run-time. All the other JVM bytecode instructions for method invocation, like invokevirtual
, hard-wire the target type information into your compilation, i.e. into your class file. Let's look at an example.
Tuesday, January 17, 2012
Java 7: How to write really fast Java code
ThreadLocalRandom
which is new in Java 7 to generate random numbers. I have analyzed the performance of ThreadLocalRandom
in a series of micro-benchmarks to find out how it performs in a single threaded environment. The results were relatively surprising: although the code is very similar, ThreadLocalRandom
is twice as fast as Math.random()
! The results drew my interest and I decided to investigate this a little further. I have documented my anlysis process. It is an examplary introduction into analysis steps, technologies and some of the JVM diagnostic tools required to understand differences in the performance of small code segments. Some experience with the described toolset and technologies will enable you to write faster Java code for your specific Hotspot target environment.
Wednesday, December 28, 2011
Java 7: Understanding the Phaser
Phaser
. If you need to wait for threads to arrive before you can continue or start another set of tasks, then Phaser
is a good choice. Here is the listing, everything is explained step-by-step.Thursday, December 15, 2011
Java 7: Fork and join decomposable input pattern
Friday, December 9, 2011
Java 7: Fork and join and the jam jar
Friday, December 2, 2011
Java 7: Project Coin in code examples
Tuesday, October 25, 2011
Threading stories: volatile and synchronized
volatile
modifier I have introduced a little program that illustrates the behaviour of volatile
in a Java 6 (26) Hotspot VM. Since that day I had some interesting discussions that I wanted to share in this blog. It adds another valuable insights on the volatile
modifier.Wednesday, October 19, 2011
Threading stories: Why volatile matters
volatile
modifier. I don't know why, but I never had problems without volatile
, so maybe I thought it could not be so relevant. I've suddenly changed my mind when I first analyzed a wierd behaviour of an application that only existed when the application was deployed to a server JVM. Todays JVMs make a lot magic stuff to optimize runtime performance on server applications. In this blog I show you an example to get fimiliar with problems that arrize in multithreaded applications, when you don't recognize the importance of understanding how Java treats shared data in multithreaded programs.Friday, September 30, 2011
Benchmark series on simple caching solutions in Java
ConcurrentHashMap
. In this blog I publish the first results. I have used Heinz Kabutz' Performance Checker to do this. I also added some features based on my readings of this article series.