Views

Developers Traps

Share |

Contents

Traps to be avoided

Date format not thread safe

  • Keep in mind that several threads cannot use the same DateFormat object (can throws OutOfBoundsException), this applies to locale and addition formatters provided by jajuk (see how to format dates)

canWrite() method

SteppedComboBox fonts

  • Do not use custom font for stepped comboboxes : the stepping doesn't work anymore for unknown reason

Reading events properties

  • If an event contains an non-string property to read, use get(<property>) to retrieve it. When using getProperty() method, the Property class returns null.

Trailing zeros

Do not use trailing 0 in integers like in :

throw new JajukException(005);

but instead :

throw new JajukException(5);

because 005 != 5 (octal)

Char issue

Avoid using chars in strings building because a char + int + string => (int) + string. Example:

String s = '('+33+") foo)"

How to avoid memory leaks ?

  • Use jconsole and/or visualvm to track class with high generations value (generations value is the number of concurrent generations alive). Use snapshots to compare generations values.
  • Avoid using static inner classes : once loaded, they are never unloaded and are kept on non-heap space.
  • Avoid using too mush singletons pattern and static attributes
  • Always clear collections aftyer use if these collections are classes attributes.