Java tips & tricks

Exception while connecting from within mod_jk to mysql

During the connection fase the following exception is raised:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near '????????????????' at line 1
This can be solved by adding "useJvmCharsetConverters=true" to the connection-string.
        String url="jdbc:mysql://";
        Connection con = DriverManager.getConnection(url);

After creating about 1200 threads, a "java.lang.OutOfMemoryError: unable to create new native thread" exception is thrown

This exception is then thrown regardless of the '-Xmx...MB' setting.
It looks as if this is OpenJDK related: in my own tests I found I could not create more than 1200 threads, even with the -Xmx1024MB setting when using OpenJDK (OpenJDK Runtime Environment (IcedTea6 1.6) (suse-0.1.3-x86_64)). When using the SUN JVM (Java(TM) SE Runtime Environment (build 1.6.0_16-b01)), creating 6000+ threads ran fine!

Using 'Graphics' object on a headless system

Run your Java program with -Djava.awt.headless=true.

Programs take very long to start

This might be related to Java doing things with IPv6. Strace (or truss) well let you know for sure. If that's the case, add to the Java-commandline.

Applet not displayed in browser on MacOS

This is caused by an incompatible JRE version in the browser.
Try upgrading to snow leopard or try compiling your applet with:
javac -source 1.4 -target 1.4
This won't work when you used 1.5 features like enums.


Do not use Math.pow(x, 2.0), use x * x instead. The second one is 10 times faster (JVM version 1.6.0_13 on an Intel Q9450).

House for sale in Gouda, the Netherlands ("Holland"):