May 16th, 2008

More serious blogging…0

I’m one of the four main bloggers at Four Starters, where I just posted my first article. This blog will stick around but with less traffic and only for programming related material.

Queues and stack traces12

A lot of java apps (in particular Lombok, the single thread webserver I’ve been working on, but there are lots of apps where this can help) employ queues and separate threads to handle the stuff inside them.

One of the problems with this is utterly pointless stack traces. The stack trace is simply of the logistics around the daemon thread handling the queue, and not the code event where the faulty job got introduced to the queue.

A simple way to help yourself is to store a stack trace at the time the job is introduced to the queue. e.g:

public void addToQueue(Job job) {
    Throwable stackOnQueue = new Throwable();
    synchronized ( this ) {
        job.setStackOnQueue(stackOnQueue);
        jobQueue.add(job);
        notifyAll();
    }
}

public void run() {
    while ( running && !Thread.interrupted() ) {
        synchronized ( this ) {
           Job nextJob = jobQueue.poll();
           if ( nextJob != null ) try {
               handleJob(job);
           } catch ( Exception e ) {
               //e's stack trace here isn't of much use...
               //but job.getStackOnQueue() is much more useful!
           } else wait();
    }
}

Hacking away at GWT5

There’s a lot of progress going on integrating Script.aculo.us and YUI-EXT (which are both effects and widget libraries for web pages, targetted at writing vanilla javascript) into GWT - the combination java to javascript compiler and widget/effects library by Google.

One of the strengths of GWT is that, due to java’s explicit static typing (I’ve talking about this before) GWT can determine, with very fine granularity, which code is actually used, and which code isn’t.

This is nice in reference to effects/widget libraries, because not sending to the browser the code for the effects/widgets that you don’t use is a nice boon; you can in effect use such a library even for just one small effect without worrying about forcing another 50k to download for every client. The digg homepage could use some of this treatment, which clocks in at a 3MB download for the whole thing.

So, while wrapping around YUI-EXT or scriptaculous is certainly a fine effort, the real solution is to rewrite it all in GWT code.

Here’s some effects I quickly hacked together: Source + demo: tipit-gwtlib.

Imhotep theme designed by Chris Lin. Proudly powered by Wordpress.
XHTML | CSS | RSS | Comments RSS