[JAVA] Big performance improvements, mainly in single-thread
but also in multi-thread