Better fix for java:terminate(...) and gc problem.