2016-10-26

Mysql: MySQL Workbench 6.3 and the Options File editor

Yeah, today it wrote the query_cache_wlock_invalidate (boolean) parameter to the my.cnf file and forgot to give it some value.

You won't believe what happened next... MySQL did not woke up after the restart... FML

2016-10-25

Java: About invoke bytecode instructions

You can find the Java bytecode instruction here.
  1. invokestatic: This instruction is used to call static methods on a class. It is determined at compile time, which method will be called.
  2. invokevirtual: This calls public and protected instance methods. Of course, it needs the instance reference on the stack, and also does the runtime binding (which adds overhead compared to invokestatic, but this "overhead" is not something you want to micro-optimize by design) for method dispatching. In fact, invokevirtual is not a true instruction, the actual steps taken are determined at runtime (cf. invokestatic) by the JVM, and can even involve Reflection, maybe even prohibit JIT in-place optimizations. Note, that the method handles are determined compile time, just the call path and strategy is determined at runtime (see: polymorphism).
  3. invokeinterface: Similar to invokevirtual, just the method dispatch is based on an interface, not a class.
  4. invokespecial: Calls the constructors (as they have special names that can't be referenced from plain Java code directly [on purpose]), also private and super (class parent's) methods.
  5. invokedynamic: This was introduced to address the "performance issues" of invokevirtual in a way, that the first call is executed as an invokevirtual, and the selected call path is stored for that invocation for subsequent reuse. In fact, this dynamic method resolution works with method handles obtained runtime (see: java.lang.invoke.* methods), not at compile time.
How does this affect you? Make your methods static if possible, but don't be overzealous! That's never a good approach.

2016-10-14

Java 8: Glossary of a session

OCP
Open/Closed Principle
Open for extension, Closed for modification Principle
SAM / Function Object
Only one method in a class. See: @FunctionalInterface; eg. Callable or Runnable.
Covariant Overriding
During inheritance, an overridden method's return type can be changed to one of it's subtypes. Eg. when overriding clone().
Erasure
Type parameters are removed from the types in the class bytecode.

2016-10-13

Java: PMD AvoidStringBufferField resolution

Inside an inherited code, I got a warning from PMD, stating
StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).

StringBuffers/StringBuilders can grow considerably, and so may become a source of memory leaks if held within objects with long lifetimes.
So I went ahead and replaced the StringBuilder with a StringWriter. It even has the same append method signature for strings :D