All entries for January 2006

January 30, 2006

Utterly underwhelming ;)

Follow-up to Spring User Group (or maybe just general Java); interested? from Colin's blog

No one?

Come on guys/gals; I know there are a lot of techies out there…. you can't hide forever :)

January 26, 2006

Spring User Group (or maybe just general Java); interested?

Hi one and all,

I am interested in finding/starting a Spring ( User Group, or maybe just a general Java User Group.

Idea would be to meet regularly (maybe monthly), discuss latest framework/Java developments, demonstrations of cool code, questions (and hopefully answers) and most importantly, eat lots of pizza.

Anyone interested?

Let me know please :)

January 24, 2006

Useful real life coverage of jdk5 features

Writing about web page

Some useful (but you have to read a bit before you get there ;)) info about the (not so) new features in jdk1.5

January 23, 2006

What on Earth is this?

So I mistakenly wrote the following code:

    private <List>ContentFetcher getContentFetchers() {
        return null;

instead of

    private List <ContentFetcher> getContentFetchers() {
        return null;

and guess what Eclipse moaned about? Nothing, absolutely nothing. Code completion shows that the method returns a ContentFetcher, so what does "" do? Apparantly nothing :)

Weird ;)

OK, go on then smarty pants and tell me what it is doing :)

January 19, 2006

Living on the edge :)

So in the project I am working on we have a bit of code which checks the userAgent and decides whether it is "good" or "bad". It uses this information to determine the appropriate rendition, but that is irrelevant.

We have (as all good developers should ;)) and interface:

  public interface UserAgentChecker {
    boolean isGoodUserAgent(final String userAgent);

with a single implementation. Given that the number of unique user agents is quite small, but each user agent will be used a large number of times, (i.e. unique user agents would be Netscape, IE etc.) this is an ideal candidate for caching (high reads, low writes).

Also, given that the "goodness" or "badness" doesn't change, there is no need to worry about stale data. Even better.

Our existing implementation uses regular expressions which, considering their power are extremely efficient, but they are still (relatively) expensive.

To implement the cache I could use AOP, or I could use a simple decorator. Given that we are overriding all the methods (there is only one!) and the caching (at the moment) isn't reusable by lots of different things, I decided to go with the good old decorator pattern, i.e.:

  public final class CachedUserAgentChecker implements UserAgentChecker {
    public CachedUserAgentChecker(final UserAgentChecker decorated) {
      this.decoratedUserAgentChecker = decorated;

Because the size of the cache will be very small (tens of userAgent strings) I decided to go with a simple Map whose key is the userAgent and the value is Boolean.

Now, the million dollar question :)

Should that map be synchronised :) According to the Javadoc HashMap isn't synchronised so in theory if two threads execute a containsKey() or get() or put() it could throw a ConcurrentModificationException(), but the javadoc really isn't clear on whether it would.

I could do my own synchronisation, or I could use Collections.synchronisedMap(..) but this will all have a minor impact on performance.

So, should I or shouldn't I? I wrote a little test harness which started 100 threads which all did puts/gets/containsKey() and didn't get any concurrency issues.

So, have any of you ever run into concurrency issues using a standard HashMap?

At the moment the production code isn't synchronised ;) Hope I don't get sacked :)

January 18, 2006


Writing about web page

Hey, I could do that; not!

Sure is inspiring though ;)

January 2006

Mo Tu We Th Fr Sa Su
Dec |  Today  | Feb
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31               

Search this blog



Most recent comments

  • Interesting… While I'm not completely convinced in such microbenchmarks, I'm pretty sure that 1ms … by Alexander Snaps on this entry
  • Hello. I bought the book yesterday. I was trying to find the source code for chapter 11 and chapter … by Suleman on this entry
  • by live mashup demo on this entry
  • Thanks mate ….. This blog was really helpful. by Maaz Hurzuk on this entry
  • Ty. Not directly helpful for my problem, but pointed me in the right direction. You will also get th… by Mike E. on this entry

Blog archive

Not signed in
Sign in

Powered by BlogBuilder