Sunday, April 7, 2013
Brief Introduction to Java Classloader
Tuesday, March 26, 2013
Java Concurrency: Fair Lock
java.util.concurrent.locks.ReentrantLock has a constructor with a boolean parameter. With this constructor, you can have fair lock mechanism. ReentrantLock has a queue to contain threads which want to acquire this lock. When a thread releases this lock, then the header will acquire this lock if the queue is not empty.
Tuesday, March 19, 2013
Use jOOQ to mock JDBC
Tuesday, March 12, 2013
SIP Servlet 2.0 POJOs
The link of the draft of SIP Servlet 2.0 POJOs: http://java.net/projects/sipservlet-spec/lists/jsr359-experts/archive/2013-02/message/41
Thursday, March 7, 2013
MMIM MSRP EOF Exception
Template Method pattern in Java - Two Ways
Saturday, March 2, 2013
Java Concurrency: Thread State
In Java, a thread has 5 kinds of states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED. When you execute Thread.sleep(long), the current thread status will transform from RUNNABLE to TIMED_WAITING, and the current thread will give up CPU resources to another threads. But the current thread will not give up the monitor.
When execute Object.wait(), the current thread will become to WAITING state ( Object timed wait will make thread to TIMED_WAITING state ). But different with Thread.sleep(), Object.wait() will make thread to give up the monitor.
When your code use synchronized keyword try to acquire a monitor but blocked, the current thread will be at BLOCKED state. At that moment, the thread cannot respond to the interruption. But at WAITING and TIMED_WAITING state, a thread can have chance to respond to the interruption.
Different with synchronized, Lock.tryLock(long time, TimeUnit unit) can respond to the interruption. So use Lock in Java 5 concurrent is a way to avoid dead lock.
Friday, January 18, 2013
Next stop - Spring 4.0
Thursday, January 17, 2013
Preserve Whole Object
And this refactoring (Preserve Whole Object) can also improve the readability.
And when you apply "Preserve Whole Object", you find the invoked method need a lot of attributes of this object. You need to consider use "Move Method" to do the code refactoring. So "Preserve Whole Object" can help you to know whether your code need to do "Move Method" refactoring.
Friday, January 11, 2013
@Resource, @Inject and @Autowired
Tuesday, January 8, 2013
Spring Migration Analyzer
Wednesday, January 2, 2013
How to run Tomcat7 Maven plugin
Yesterday when I studied Spring MVC showcase I found if you run "mvn tomcat:run", the async samples would not be successful. When I checked "pom.xml", I found it used old version Tomcat Maven plugin.
Then I change it to latest Tomcat Maven plugin. The artifact id is tomcat7-maven-plugin. (You can get it on search.maven.org, so I will not show the code.). Then run "mvn tomcat:run", but still failed. I found this plugin still use Tomcat6, not Tomcat7. Later, I tried "mvn tomcat7:run". Then I found this time the plugin used Tomcat7 run the application. So when you use Tomcat7 Maven plugin, you have to run "mvn tomcat7:run".
Monday, December 31, 2012
Spring Java-based configuration
From Spring 3.0, we can configure our Spring application with a new way: Java-based configuration. With Java-based configuration, you can migrate all XML configuration files to configuration Java class. With that, you can avoid typing errors and enjoy the programmatic features. Though some IDEs, like Intellij IDEA can make you away from typing errors, but with Java-based configuration, you can enjoy this feature on all of IDEs, even with text editors.
In my opinion, Spring configuration best practice is use Annotation configure your own code. For 3rd party classes, Java-based configuration is a good choice.
The following are some samples from Spring 3.0 Documentation.
XML-based configuration load Java-based configurationJava-based configuration load XML-based configuration
Specifying bean scope
Saturday, January 17, 2009
An Demo App Developed with Grails
You can find the source code in Google Code's SVN. Anyone interested in Groovy, Grails and Seam can communicate with me.
The next step plan is to rewrite the 'seambay' example of Seam Framework in Grails.