All posts by Nick Lothian

Java Projects Someone Should Write

I often come up with “really good ideas” for programming projects (many may not actually be good ideas, but
who's counting..). Since I don't have time to do these projects, perhaps someone else will. Let me know if you finish any of
them….

Aggregator using the Rich Client Platform & Classifier4J

JMX console for Eclipse

Proper java launching exe's, which examine the hardware they run on and pass appropriate arguments to the VM. There
would be separate launchers for different configs, eg “javaserver.exe”, “javaclient.exe” etc.

A better build tool (and/or decent docs for Maven)

A taglib based Portal for Apache Pluto

An application infrastructure thing that downloads Jars from the Maven repositry as they are required (aside – that
repositry really should be mirrored)

Sync4J – a java library that will sync two directories by using various methods including email.
(yes, I know about RSync in Java, but the email thing is important to me).

A Velocity based XDoclet replacement that actually works. It should include
a translation tool to translate xdt XDoclet files into Velocity templates.

An XDoclet template for JSR168 Portlets

A web application framework that merges the web request<->response model and
messaging (possibly JMS): A request is sent down a message bus, and services
on the bus can subscribe to particular request types (think specific URLs).
The services modify the application data model, and when all services have
processed the request a response in generated, which is sent back up the bus
for processing by presentation services.

Dashboard in Java

A project like MS Application Blocks, but for J2EE (and don't suggest the
“Core J2EE Patterns” book. That book is good, but the code isn't alway
exactly right).

Something which exposes JMX attributes as Windows Performance Monitors
(think JDK 1.5 VM as well as app server monitoring).

AustDevBlogs.com.au: An Australian developer blogs aggregator.

A Java Servlet Filter version DOSEvasion

I'll update this post with more projects as I remember them.

Busy Busy Busy…

I appear to be running a deficit in the attention budget division, as the
lack of updates here shows.

I've been busy at work finishing off a portlet based product (running on
Pluto), which has gone pretty well. Sometime I'll get the long blog post I
have about developing portlets out of my head and into pixels..

In somewhat related news, I am now a committer on Apache Pluto,
which is nice. I'll be
updating the documentation with some patches I've done as soon as I get it all set up.

I also have done some work on a simplified vector space search algorithm
for Classifier4J, although nothing
I can commit yet. It is looking pretty promising, though – it is very fast,
but useful for a different class of problems to the Bayesian classifier in
Classifier4J.

I'm also writing a list of project I'd start if I had time. The fact that
I haven't even had time to post the list yet
kind of indicates the likelihood of me getting anywhere on them, but maybe
someone else will find one interesting and write it for me.

Commons-Collections 3.0

In case you didn't notice, Jakarta Commons Collection 3.0
has just been released. I think it is probably fair to say the the reception
it got
wasn't 100% favourable.

While I don't really want to comment on the release (although I can't resist pointing to this), what I do find
puzzling is the lack of discussion on the
commons-dev
mailing list
about this. I would have thought that one developer would perhaps consider the possibility that they should
listen to feedback from their users.

I can understand that they must have built up some kind of immunity to bile by now, but some of the ideas and comments
on TheServerside were… well.. kind of valid..

JDK1.5: java.lang.instrument

The java.lang.instrument package allows a programmer to modify classfiles
as they are loaded. No API for doing the modifications is supplied, but you
can use ASM or BCEL etc to do that. This example prints out class names as
they are loaded.


package inst;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;

public class Instrument {

    public static void premain(String options, Instrumentation ins) {
    	ins.addTransformer(new Logger() );
    }

    public static void main(String args[] ) {
    	System.out.println("Hello World" );
    }

    public static class Logger implements ClassFileTransformer {
        public byte[] transform(java.lang.ClassLoader loader,
                java.lang.String className,
                java.lang.Class classBeingRedefined,
                java.security.ProtectionDomain protectionDomain,
                byte[] classfileBuffer) throws IllegalClassFormatException
        {
            System.err.println(className );
            return null;
        }
    }

}

It is run using the new javaagent parameter:

   java -javaagent:inst.Instrument inst.Instrument

Output:


    java/lang/StringCoding
    java/lang/ThreadLocal$ThreadLocalMap
    java/lang/ThreadLocal$ThreadLocalMap$Entry
    java/lang/StringCoding$CharsetSD
    java/lang/StringCoding$StringDecoder
    Hello World

I presume that classes like java.lang.String are loaded prior to the agent
class being hooked up. Also, beware that
it is possible to deadlock the classloading mechanism if you aren't careful
– only modifying classes that don't match a regexp like
“java.*|sun.*|javax.*” is a good idea!

JDK 1.5: Monitoring the JVM

JDK 1.5 contains a number of useful interfaces to monitor the performance of the JVM. This includes
support for both Memory and CPU usage. These metrics are exposed via JMX as well as via plain interfaces
in the JDK.

The code below iterates over the different elements in the memory pool and prints out their
current statistics.


    List mpMBList = ManagementFactory.getMemoryPoolMBeans();
    for (Iterator iter = mpMBList.iterator(); iter.hasNext(); ) {
        MemoryPoolMBean element = (MemoryPoolMBean) iter.next();
        System.out.println(element.getName() + " " + element.getPeakUsage());
    }

Output:


Code Cache initSize = 196608, used = 450112, committed = 458752, maxSize = 33554432
Eden Space initSize = 524288, used = 518712, committed = 524288, maxSize = -1
Survivor Space 1 initSize = 65536, used = 0, committed = 65536, maxSize = -1
Survivor Space 2 initSize = 65536, used = 65528, committed = 65536, maxSize = -1
Tenured Gen initSize = 1441792, used = 42944, committed = 1441792, maxSize = 61997056
Perm Gen initSize = 8388608, used = 1718928, committed = 8388608, maxSize = 67108864

The information you get is similar to what you can get using the
JVM Stat tool in Sun's
JDK 1.4.2 VM.

Talking about Java 1.5

As you may have noticed, Sun has released an early version of JDK1.5
(which I appreciate very much). Initially Javalobby publicised this
mostly
, and insisted that downloaders are bound by a non-disclosure
agreement (which I ranted about previously).

However, now Sun
have published a link to the download
, with no mention of a NDA. There
is some quite dense language in the click-thru licence about confidential
information, but I don't think that is supposed to be a NDA (INAL,
though). In any case, exactly
the same language is used
for the JDK1.4.1 download.

It is worth pointing out that the bug database for
1.5
is public, too.

Anyway, unless someone (preferably someone from Sun) can let me know I
shouldn't, I intend to start talking about 1.5

Eclipse Modeling Framework

If you are interested in code generation, model driven architecture or in metaprogramming generally, have a look at
Eclipse EMF.

To put it simply, you can create an entire Java GUI application (okay – an Eclipse Plugin) by defining your model in
Java classes
(or it can import a Rational Rose model
or use the
Omondo UML plugin for Eclipse).

I found the existing functionality amazing: Following the tutorial
it took me 30 minutes to have a fully functioning Eclipse plugin that allowed data editing and persistance to XML. The only
code that I needed to write was some interfaces that defined how my data interacted using the JavaBeans model, and everything else
was generated.

The crazy thing is that this application generation I'm raving about is really just a sample for the tutorial – developers
are supposed to use EMF as a tool to generate code however they like. Anyway, if I was considering writing a XDoclet plugin
or something similar right now I would look very hard at using EMF instead.

Java/Linux performance improvements

I was reading Joseph Pranevich's “What's new in Linux 2.6 and I noticed
this:

Another major change in the 2.6 release, is that the kernel's internal threading
infrastructure has been rewritten to allow the Native POSIX Thread Library (NPTL) to run on top of it.
This can be a major performance boost for Pentium Pro and better processors in heavily threaded applications,
and many of the top players in the “enterprise” space have been clamoring for it. (In fact, RedHat has
already backported the support to Linux 2.4 and includes it starting with RedHat 9 and Advanced Server 3.0)

I got a bit excited about this, because the dirty little secret of the “Linux/Java anti-Microsoft kabal” is that Java
on Linux usually isn't comparable to Java on Windows on the same hardware (note, I said usually!). A little searching
came up with Red Hat Linux 9 and Java 2 Platform,
Standard Edition 1.4.2: A Winning Combination
, which mentions:

On a 2 X 1.6 Ghz P4 Xeon system, time to completion was 191% faster with J2SE 1.4.2 running on NPTL,
compared with J2SE 1.41 running on the original Linux threads.

Is anyone familiar enough with this to comment as to how real this improvement is? I'd love to see someone run
ECPerf on Windows/Java 1.4.1, Windows/Java 1.4.2, Linux/Java 1.4.1 and Linux/Java 1.4.2 on identical hardware and
see how it comes out. Any takers?

Isn't it ironic?

Somewhat ironically a day before my previous post,
Dare Obasanjo replied to
a blog complaining about MS
Architects posting about technologies that aren't ready for production yet.
. The irony that I still can't talk about JDK1.5,
despite its release date being next year is – if not Shakespearian – at least more than Morissettian.

(Those of you not interested in the hostory of various websites may want to leave now)
Incidentally, “Back in the day” I was pretty active on K5, and I remember when Dare joined (which, despite
his low uid was quite a long time after I joined – my id was in the 200's and his is over 1800). I thought he
was just another punk hacker who thought he was too cool for /. until he started posting a few stories. They always
impressed me, and I had pretty high standards. He posted some when he interviewed at Microsoft, and he thought he
was going to be working on Data Access stuff, which I found pretty interesting. Unfortunatly he went and did that XML crap instead, so
I stopped reading his stuff for a while… ;-)

JDK1.5 Alpha Rant

Sun made the JDK1.5 Alpha available today through JavaLobby. I think that was a great move on their part, but I do think
having to click through a big disclaimer promising not to talk about it was a bad move. I'm sure Sun was worried about
people complaining about bugs or bad performance or something, but we all understand this is an alpha release, right?

Alphas always have bugs and performance problems, and those things are easily solvable. Much more important is the marketing of this,
the most significant release of Java since 1.2. There is an enormous set of wonderful features coming in Java 1.5, and here I am enjoying
them all, and dying to proclaim that Java 1.5 is the one true development environment, and it kicks the .NET's butt. Unfortunalty, I can't tell you that,
or anything else about it really – and this is for a product that is probably only 6 months from release!

Meanwhile, our friends at Microsoft have thousands of people writing about Longhorn, Avalon, WinFS etc, etc – all of which
won't be released until 2006 at the earliest. That is Sun's problem, and I hope they realise it.

It was a nice Christmas present, though – even if I won't get to play with it for a few days.