All entries for Monday 27 March 2006

March 27, 2006

Threading in JBoss, hibernate + spring

The project I am currently working on has an OM which looks like:

page -> content -> contentFetcher

The page typically has 4 contents (links, toolbars, main and rhs) which are sequentially loaded. This seems like a good candidate for threading; there are no dependencies between them and they are each potentially expensive to created (coming from remote servers etc.).

As an experiment I wrapped added the call to retrieve them in it's own thread and deployed. Unfortunately it all went horribly wrong….and (I think) it is because we are using spring OSIV which creates a single session for the entire thread. The stack trace is:

        at java.util.HashMap$HashIterator.nextEntry(
        at java.util.HashMap$
        at org.hibernate.pretty.Printer.toString(
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListen
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(
        at org.hibernate.impl.SessionImpl.flush(
        at org.hibernate.impl.SessionImpl.managedFlush(
        at org.hibernate.transaction.JDBCTransaction.commit(
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(

which is a shame.

(As an aside, it is OK to create threads within JBoss, or rather to retrieve threads from a custom threadpool; thus allowing JBoss to shut down without your threads holding anything up.)

I am sure I can work around this, and I have only spent 5 minutes on this so far, but I don't think we will be able to use SessionPerView…..

P.S link

Charsets ; I hate them :(

So the project I am working on uses a number of technologies including JSTL and freemarker.

Somebody had entered the following character: "" which was displaying perfectly in JSP, but freemarker was replacing it with "?".

Of course I thought, it must be freemarkers fault :) I was meticulously careful about never converting a byte[] into a String using the string constructor unless the charset was specified, but I never realised you had to do it the other way as well :( When calling getBytes(), the encoding of the string is completely ignored and the platform default is used…. Why?

So the following will do bad things:

  new String(new String("some string with a funny character ", encoding).getBytes(), encoding);


The problem was also a little bit more interesting because on windows machines the default platform is unicode based, on solaris it isn't, so the problem only exhibited itself on solaris.

I have (I am ashamed to say) never really delved into the joy of charsets and text encoding, instead preferring to stick my head in the sand. Luckily Chris May sits next on the desk next to me :)

March 2006

Mo Tu We Th Fr Sa Su
Feb |  Today  | Apr
      1 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