Deprecated Garbage Collections – Kenny Lee Chee Wei

A truckload of garbage by Kenny Lee Chee Wei

Archive for the ‘Java’ Category

Ajax App Server? – AjaxToaster

with one comment

AjaxToaster is an Ajax application server which makes it easy to create RESTful web services for rich web client applications. It runs under any of the main Java servlet containers (tomcat/glassfish/websphere/jboss/jetty)”

Still in RC though. I haven’t managed to take a closer look, but the request/update urls doesn’t look too restful to me.

http://localhost:8080/toaster?service=meetings/UpdateMeetingRoom&inputjson={"Room":[{"RoomCode":"AZALEA","RoomName":"The Azalea Room"}

Hmm, not too sure anyone had a go at this project.


Written by kennii

August 15, 2008 at 4:26 am

Posted in Java

Tagged with , ,


leave a comment »

  1. String s = "f" + "o" + "o"
  2. is faster than

    String s = "f";

  3. The comparison
    ('a' == s.charAt(0))
  4. is faster than


  5. The StringBuffer default capacity is 16. If your string is going to be larger than that, you might as well reserve a larger capacity by passing a realistic length such asStringBuffer sb = new StringBuffer(1024);

Written by kennii

August 9, 2007 at 5:02 pm

Posted in Performance

Spring Hibernate DAO Implementation with interface

leave a comment »


Assuming we have a module called Account Management in our project called foo,

We might can make use of the following package structure.

  1. foo.service.AccountManagement
  2. foo.service.AccountManagementImpl
  3. foo.dao.AccountDAO
  4. foo.dao.hibernate.AccountDAOImpl (In this case hibernate)
  5. foo.model.Account

Sample Spring-Hibernate Hierarchy UML

Spring Wiring

<bean id="accountDAO" class="rb.dao.hibernate.AccountDAOImpl"></bean>

<bean id="accountManagement" class="foo.service.AccountManagementImpl">
<property name="accountDAO">
<ref bean="accountDAO"/>

So note that you can replace the accountDAO with some other implementation class, probably using pure JDBC or ibatis.


As the experts say, always code to interfaces to cater for different implementations.

Written by kennii

August 7, 2007 at 9:52 am

Posted in Java, Spring Framework

Marshalling Objects To/From XML (Java and Python)

with one comment

Python (Using PyXML)

# Install PyXML from

from xml.marshal.generic import Marshaller, Unmarshaller

class Company:

def __init__(self, name, year_founded, ceo): = name
self.year_founded =year_founded = ceo

def __str__(self):
return "%s %s %s" % (, self.year_founded,

c = Company('Google Inc.', '1998', 'Eric Schmidt')

# Marshalling
marshal = Marshaller()
xml = marshal.dumps(c)
print xml

# Un-Marshalling
um = Unmarshaller()
obj = um.loads(xml)
print obj

Java (Using XStream)

The people at ThoughtWorks makes it easy. Just read here.

Written by kennii

August 7, 2007 at 7:35 am

Posted in Java, Python

Collaborating threads using CyclicBarrier (Java 5)

with 6 comments

Recently, i came across this problem.

Write a java program that prints out the line “Started” to the console and then creates 10 threads. Each thread should print the lines “Thread x started”, “Thread x finished” where x is the thread number (0 to 9). The program should then print the line “Terminated”. No thread should print the finish message until all threads have printed the started message. The final “Terminated” message should be printed as soon after the last finished message has been printed.

The interesting thing is all the threads have to wait for each other to reach a common point before being allowed to terminate. This common point is known as the CyclicBarrier in java speak.

I did some quick research and came across this class under the java.util.concurrent package. So using this class i managed to complete this problem in about 1+ hrs (Includes refreshing my memory of threads =D).

Full Source Code (Server and ServerThread)

Written by kennii

August 7, 2007 at 7:02 am

Posted in Java