Tuesday, 10 July 2012

Do not implement/generate getters and setters!

Project lombok is a java library which prevents you from implementing or generating getters and setters for POJOs. You just add annotation on the class or on the individual property. Having such code, that just gets and sets properties is unmaintainable and bad for class clarity.
This library has also some other useful features like f.e. @Delegate - annotation that ease creating classes with delegation methods.

Here you can see examples:http://projectlombok.org/features/index.html

Tomcat startup takes extra 3 minutes. Why?

I have faced a problem of long startup of tomcat 7 that used jvm 7 on the linux server. Tomcat without any application started over 3 minutes. In the catalina.out log there was a message:
May 22, 2012 10:02:48 AM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation
using [SHA1PRNG] took [131,611] milliseconds.
This problem appears due to Tomcat 7+ usage of SecureRandom class to provide random values for its session ids. You can use non-blocking setup, just set the following system property: -Djava.security.egd=file:/dev/./urandom
You can read more on this subject in tomcat wiki: http://wiki.apache.org/tomcat/HowTo/FasterStartUp

Monday, 9 July 2012

Invoke dynamic in java 7

Recently I have attended Confitura 2012 a Java Conference in Warsaw. One of the most interesting lectures was the one made by Waldemar Kot. He has introduced subject of the new instruction in Java 7: Invoke dynamic.
He has shown that it has a very big impact on the java development, not only on dynamic languages on JVM. Using invoke dynamic in java you can have dynamic behavior with speed comparable to static invocation.
You can see examples and benchmarks here: https://github.com/waldekkot/Confitura2012_InvokeDynamic

Wednesday, 4 July 2012

Let's try implement an algorithm

If you want to train implementing algorithms you can go to the Project Euler.

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.

Corkboard online

If you want to have a place to stick your notes in the virtual then you can try: http://corkboard.me

Rod Johnson has left SpringSource

Rod Johnson the father of Spring, co-founded SpringSource has decided to leave SpringSource. He grew a company building a Spring Framework a better Java Enterprise Edition.
His leaving post: blog.springsource.org/2012/07/03/oh-the-places-youll-go/

Sunday, 1 July 2012

Exposing monitoring by JMX in Spring application

To expose methods as MBeans in the Spring Application by JMX you have to:
  • Declare in the application configuration: <context:mbean-export/>
  • Annotate java class with @ManagedResource
  • Annotate getters or setters with <@ManagedAttribute>
After that you can connect by jconsole to your application and use annotated methods.
You can also use annotations: @ManagedOperation, @ManagedNotification for methods that are not setters or getters.