Short notes from a week
In my evernote I am writing notes about interesting things I have discovered in a week. I have collected many of them and I decided that I will publish them on this blog from now on. Sometimes I will add some older ones in order to migrate them from evernote.
Garbage collecting live live objects.
Another JVM surprise. From JLS 12.6.1.
Optimizing transformations of a program can be designed that reduce the number of objects that are reachable to be less than those which would naively be considered reachable. For example, a Java compiler or code generator may choose to set a variable or parameter that will no longer be used to null to cause the storage for such an object to be potentially reclaimable sooner.
This means that if instance is not reachable it can be collected even if it is assigned to local variable or its method is being executed.
Relevant SO thread.
Date format yyyy vs YYYY
Be aware of the nuance of these two formats. Original post. YYYY represents ISO week date which might not be the same as an actual year. This reminded me post Falsehoods programmers believe about time.
Foreign data wrappers in Postgres
Postgres is capable of mapping external source of data to tables. This is an example of filesystem wrappper. What is very interesting that is not only readonly but also writable and transactional! There is a lot of “exotic” wrappers on the internet, facebook wrapper for example.
Do not use count(*) for existence check
As usual great post from jooq with follow up post. Using count when the goal is existence checking is not a good idea.
Exists query can exit if any matching row was found.
Count must load all matching rows in order to return.
- maximum length of string in java is limited to Integer.MAX_VALUE, because of indexing the underlying char array with an int.