Wednesday, 23 April 2008

Some quick notes on Db Connection pooling in Glassfish

To set up a Glassfish connection pooling and JNDI datasource, accessible in your web app, the following things need to be done (tried with Glassfish v2):

Db drivers:

Ensure the relevant JDBC driver is in the Glassfish classpath. I ensured the <glassfish_home>/lib directory contained the latest MySQL J connector. You may need to restart Glassfish (you probably will if you change the classpath).


Connection Pool:

Set up a connection pool in the Glassfish admin interface (under Resources\JDBC\Connection Pools). In my case for MySQL I was happy to use the defaults initially, which includes:

  • Datasource classname: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
  • Resource Type: javax.sql.Datasource

Give the pool a sensible name.

Once you have set this and the connection details (host, username, password etc) you can use the Ping feature to check the connectivity. If you get errors regarding classes not found, check your classpath / location of the JDBC library jars - possibly restart Glassfish if you have not already.

Once you have a successful ping, you can move on to configuring the JNDI resource:

JNDI resource:

Under the Resources\JDBC\JDBC Resources set up a JNDI resource to the pool you just configured (by name), give the JNDI resource a name of the form:


ensure the resource is enabled!

Deployment descriptors, configuration:

sun-web.xml - Map the container JNDI to a resource reference in sun-web.xml, e.g. something like:

<!-- Map container JNDI to resource reference -->

web.xml - Map the resource as a datasource reference in web.xml

<!-- set up resource reference for the web app -->

Application Code:

In you application code, where you get a connection, you can then use something along the lines of:

Connection connection = null;

Context env = (Context)new InitialContext().lookup("java:comp/env");

DataSource pool = (DataSource)env.lookup("myDbResourceName");

if (pool == null)
throw new RuntimeException("Unknown DataSource");

connection = pool.getConnection();
catch(NamingException ne)
throw new RuntimeException(ne.getMessage());

return connection;

Of course, modify the caught, declared to throw exceptions to suit the application design...


This article is a useful reference point, covering similar information in a slightly more verbose form:

This forum post also details the deployment descriptor configuration well:

Tuesday, 22 April 2008

Mobile development with .NET CF

It's been a few days since the last posting, I've been meaning to jot down some notes from the workshop at Microsoft (Reading Uk, 16-April-2008) before anything gets forgotten:

The aim of the workshop was to discuss the use of the Microsoft .Net Compact framework for mobile application development - including performance issues and technology features. This was in the context of both our existing Java mobile applications and choosing suitable technologies for new projects.

Java ME J9 6.1.1 performance evaluation:

To illustrate the performance we'd experienced with out Java ME applications, we demoed our existing Java ME application running on IBM J9 CDC ppro1.1 on an IPAQ. The response was actually very positive. It was suggested that re-implementing it in .Net would not yield any worth while performance gains but it would most likely create a different set of problems to solve.

We ran our app with JIT enabled, noverify and nolinenumbers but it was not compiled as a JXE on this occasion. Focus was on running application performance as perceived through the GUI (user perceptions), we did not delve into profiling information. We did not look into start up times, which are roughly similar for both Java and .Net VM based technologies.

.Net CF:

.Net CF does provide some benefits, in terms of integration with the Windows operating system (integration with the Windows menu bars etc) that would be worth bearing in mind for future projects. Specifically, notification of docking events could prove very useful in some situations. Native code is supported, as external libraries (not within the assembly) but hooks into the OS API are possible by declaring them within the .Net assembly.

Versions / dependencies:

For .Net development some care regarding versions and dependencies should be considered, for example whilst versions of Windows Mobile from 5.0 onwards _should_ support any version of .Net CF, the same can not be guaranteed for the more variable CE, where platform vendors could load a CE image missing key components required for installing .Net CF. In this scenario it would be important to discover this and engage with the customer and platform vendor to negotiate shipment of hardware with the right image components installed.

.Net CF versions:

  • 1.0 -> Old original version, no longer targeted by most development
  • 2.0 -> Good baseline with significant improvements (including performance) over 1.0 (required MS VS 2005 IDE to develop).
  • 3.5 -> Current latest version (required MS VS 2008 Pro IDE to develop).

Windows Mobile versions against their CE base:

  • WM 2003 'Ozone' -> CE 4.20
  • WM 5.0 'Magneto' -> based on CE 5 (shipped with .NET v1.0 SP2)
  • WM 6 .0 'Crossbow' -> based on CE 5.2 (shipped with .NET CF v2.0 SP2 )
  • WM 6.1 -> CE 5.x ? TBA
  • WM 7.0 'Photon' -> CE 6.0? TBD

The next major version of Windows Mobile is anticipated in 2009, but no official details were given. General information suggests a planned release of Windows Mobile 7 in the 2nd half of 2009.

CE 6.0 removes the 32 process and 32Mb restrictions:
  • The 32 process limit raised to 32,768 processes.
  • The 32 megabyte VM limit raised up to 2GB of private VM is available per process.


Microsoft SQL Server 2005 Compact Edition is available (shipped with WM 6.0). This can be used stand alone, or connected to a server side SQL server. Can be synchronised with server DB over network. Async and synch operation is possible. Loads in process as a dll (therefore doesn't use any precious process slots, but of course it will consume RAM/processor). This is a very cut down DB, things such as triggers and stored procedures are not supported.

Ajax, DOM, Javascript is possible in the browser technology (from WM 6.0 onwards).

XML is supported - recommended to use XML readers not full blown XML DOM for efficiency reasons.

XSLT - it was not clear weather XSLT was supported on the platform, either in the browser or as .Net libraries.

Windows Mobile limitations (until WM 7.0):
  • 32 process limit
  • 32Mb memory limit

Windows Mobile can close applications when it starts to run low on resources - so applications should be developed with this in mind. The OS will pick the lowest application in the Z-order that is inactive. Notification events are sent but if the application doesn't respond gracefully it could receive hard termination!

.Net development tools:

Visual studio is the only supported option (no free express version for CF 3.5 available at this time).

Optimisation tools were not generally recommended - they advocate letting it run 'as-is' but rather to concentrate efforts on getting the design right.

It was admitted that profiling tools were somewhat weak at the moment - but this is an area they are actively addressing.

Code signing:

We were warned that some platform vendors have removed the root CA from the device, which means that the only option for getting the application code signed would be to go through the device vendor (this is something that would need to be highlighted and planed in early in the project).


The need for thorough and extended testing was highlighted. Mainly due to the additional use cases that can occur on a mobile platform that are less likely or non-existent on a traditional desktop pc system, for example:

  • Memory cards being removed
  • Wireless signal poor / dropped
  • Flat battery, battery removal
  • Unexpected key presses from special function keys on the device

.Net configuration:

It's possible to configure the platform .Net CF using a configuration file:

Software updates:

Whilst there is no application support for software updates (apart from the M ) there are some software components that can be used as a basis for providing this, the Mobile Client Software Factory and the Mobile Updater.

Additional links and info:

Mobile Dev centre

Application developer consulting service

Libraries and widgets:

Mobility Marvels:

Mobile Controls:

Tuesday, 15 April 2008

Xephyr on Solaris

Searching for a better Xnest on Solaris, looking for Xephyr as a package or source to build, it turns out Xephyr is already included in SXDE.

location: /usr/X11/bin

simple usage example:

Xephyr :1 -screen 1200x800 -query localhost

This what's new in SXDE 10 guide is quite handy

Early signs of Xephyr -> ssh -> Xming on Windows seem reasonable.

ProGuard - new 4.2 version:

Evaluated the latest ProGuard 4.2 for our Java ME mobile client and it failed reporting a stack length had gone negative! Have reverted back to 4.1 for now, which seems to be working well. Will report the bug to the team.

Java ME, some J9 options worth remembering:

-Xint -> disable AOT and JIT, interpreted mode only
-noverify -> disable class verification checks (faster loaded on pre-verified code)
-Xnolinenumbers -> turn off line number debug info

Monday, 14 April 2008


Some quick prep /initial prep / background reading for the workshop with Microsoft at their Reading Campus.

Latest version is currently 3.5 (3.5 RTM 3.5.7283.0 - 2007-11-19)

Overview of 3.5 features,289142,sid8_gci1285069,00.html

You can determine the installed CF versions by running /Windows/cgacutil on the device (several versions can be co-installed without issue).

CF 3.5 goes hand in hand with Visual Studio 2008 (whereas the older 2.0 was paired with VS 2005).

Java ME JSR 216

Progress! This morning I was able to make some small changes that made a massive difference to the GUI performance of the Java ME client version of one of our products. So, I thought I'd take a moment to write up some notes on it and Mobile development in general:

Basically, in doing some testing and profiling previously, it had become evident that one of the main performance problems in JSR 216 GUI was the use of layout managers in GUI construction (especially the GridBagLayout!). I'd previously addressed all other obvious performance hot spots with optimization or re-implementation - and knew that Layout managers where one of the remain areas to re-factor. All of our GUI components were lightweight and some custom handwritten to perform a specific task. It was tempting to use SWT but wanted to keep the solution generic and AWT/LW based if possible.

Well, after identifying a spurious GridBagLayout that wasn't strictly necessary I was able to re-factor the code to remove it. The impact of this one change has been massive, with something around a 2x to 3x performance speed up and a much more responsive GUI! This is a great return for the effort involved and extent of the change.

One area that still remains is to either implement or port a StringBuilder type class to the JSR 216 platform for faster string concatenation. JSR 216 only supports StringBuffer, while this might not be a problem in most scenarios, some of the custom transparent lightweight widgets I'd written for the product need to do a lot of strings building, so it's performance is critical.

A little digging around has yielded these interesting links that I need to investigate a little more at some point:

Javolution: - which contains a Java ME library with a fast string builder class (and many other fast classes!).

String builders:

This implementation of a string builder


and also Retroweaver looks interesting. This would enable Java 5 for the mobile platform. However, I have some reservations, mainly todo with issues of performance (Mobile code tends to need to be tight and optimized for the platform). This could be a major win for porting existing code though, well worth keeping in mind.


I'll also mention that for Java ME development, utilising ProGuard has given noticeable improvements in performance on mobile platforms (as well as smaller Jars).

A word of warning, make sure the end product is tested thoroughly after optimising. Aggressive optimisation can change sometimes change expected functionality - be careful!


One other thing I came across, that I'm interested to evaluate from a performance perspective, possibly against SWT is the Java LW-VCL, which looks really quite good

Sunday, 13 April 2008

Some notes on DD-WRT

While I've got a spare minute, I'll jot down some notes on upgrading the 'La Fonera' Wireless Access Point to DD-WRT.

'Upgrading' one of these little wireless access points with DD-WRT was something I did a week or two ago, it was quite interesting. It's been working reliably with good signal and performance since. It happens to be hooked up to the Purple' network on a Smoothwall V3 firewall.'. Here are some notes and links for future reference:

The 'Fonera' comes with some built in management software. It's locked down and gets its configuration from the Fon network once it gets a connection. The unit hardware isn't too bad, wireless 802/11 b/g radio, single 10/100 Ethernet port, reverse SMA antenna connector and a power connector. The unit is small, small enough to fit in the palm of your hand!

The software loaded on to the Fonera is stored in Flash memory. The software is signed by a secret key that's never been released into the public domain.

However, various flaws in the implementation allow the Flash to be formatted and a new software image loaded instead (such as the rather good DD-WRT).

Depending what firmware the unit comes with, the exploits differ - as new versions of firmware are released they tend to close found vulnerabilities (and often inadvertantly introduce new ones instead!).

An excellent guide can be found here - I followed this and it worked flawlessly! The unit I had was revision 1 and this method worked perfectly with it.

The starting point is exploiting a vulnerability such that SSH access can be opened up, from there on in it's a matter of formatting the Flash memory and then loading the new software on the unit.

The source of the information is here

The DD-WRT site has a good guide too

The easiest exploit being the DNS exploit, where a special DNS server has been set up for public use. For this the firmware must be revision 2.

DD-WRT can be found here

Images for DD-WRT for the Fonera can be found here

Saturday, 12 April 2008

Configuring Solaris networking

Found this useful link that explains how to configure networking on Solaris both using the newer NWAM and standard networking methods:

The important bits! - some simple examples:

Set Default gateway:

#echo ""> /etc/defaultrouter

NWAM settings:

Set a static IP
#echo "nge0 static"> /etc/nwam/llp

Enable NWAM
#svcadm disable svc:/network/physical:default
#svcadm enable svc:/network/physical:nwam

Configure DNS
#svcadm disable svc:/network/dns/client:default
# echo "nameserver">> /etc/resolv.conf
# cp /etc/nsswitch.dns /etc/nsswitch.conf
# svcadm enable svc:/network/dns/client:default

Friday, 11 April 2008

SCJP 5 exam passed - woot!

It's been a busy day today, some last minute revision this morning then took the SCJP 5.0 exam this afternoon. What can I say, 3.5 hours! That's a long exam. I didn't use all the time, but still that's a quite a lot of exam for the money!

Anyway, I'm relieved and pleased to pass with 83% - not bad, could have done better but I happy with that, to be fair as a balance between time spent and other commitments.

Time to celebrate tonight I think. It's nice to get that one out of the way, will have a short break then decide which one to tackle next!

(Note to self: see if you can take a drink in next time! Got really thirsty, dehydrated and sleepy in the middle of it and no one was around so I wasn't sure if I could leave the room to get a drink, so I had to stay put - ooops!)

Notes on the exam itself:

Generally I'd say it seemed easier than I was expecting. Some questions seemed very easy, leaving me in doubt as to whether I'd missed something and then spending longer on the question than I would normally, double checking the question and answer.

The mark and review system is excellent. I also used the provided dry wipe sheets and pens to keep track of questions I wasn't sure of so I could go back. Going back to a drag and drop question does mean you lose your previous answer - but it does warn you before it happens. It seems you can only review your questions once you've gone through the whole test, so it's worth finishing with enough time left to go over the harder questions that you've marked again at the end. 3.5 hours is a long time, I suspect 3 would still be more than enough, but it's surprising how long it takes to answer 72 questions, which is a lot of questions really. If you struggled on half of them you'd be mentally exhausted by the end. The exam does concentrate quite a lot on API and syntax specifics, so you've really got to spend some time just revising and remembering those specific API classes and methods. Overall, a good experience, I'd recommend anyone in a position to do it does so, preparing for it certainly gives you a good grounding in many aspects of Java SE 5.

What to do next, that's the question. Probably one of the web developer (web components or services) ones, as they would be beneficial in my job. I guess I should do an upgrade exam from 5 to 6 (or 7!) soon too, ideally.


I've made my personal SCJP 5.0 study guide available on my personal web site - specifically here for anyone who might find it useful.

Although SCJP 5.0 is technically out of date already, v5.0 represents the bulk of the material needed in order to pass. I will at some point take the upgrade exam, but this is lower priority right now.

Thursday, 10 April 2008

Got to start somewhere!

Well, I've been meaning to keep a blog for sometime now. I created this one the other day but never seem to find the time to write in it, but then I guess you've just got "to make the time" as they say, so here's a start at it...

This is mostly going to be a Technical Blog of my activities during my working day (an on-line logbook I guess) and possibly various random things I investigate in my spare time too.

I have trouble reading my own logbook even after I've just written in it(!), so I'm hoping this will be an excellent way to keep track of all those things that 6 months later you find yourself thinking "I've already worked this out, but how did I do it again?".

My Personal web site is at - whilst long overdue for a makeover, it contains some useful content, including my SCJP5.0 guide.

Posting up html and source code in a web based blog can be problematic - code needs to be html encoded and I'm also going to surround with pre tags, to retain the formatting. HTML encoding can be done conveniently on-line, using tools such as


What am I doing today, well recently I've been evaluating VMware server 2.0 beta and beta 2 - especially as a flexible way of running Solaris 10 Express Developer - I'm looking at this for various reasons:

1. I want to evaluate the latest VMware server 2 offering in general for use when evaluating, testing and researching new OSes and software applications.

2. I want to evaluate Solaris 10 Express Developer as an excellent Java / Jave EE server platform and also a developer workstation platform (possibly shared via remote X / desktop).

I've chosen CentOS 5.1 as the host OS, and I'm running the 64 bit version.

Installing CentOS 5.1 64 bit:

Installing CentOS 5.1 64 is easy enough and there are many guides on the net so I won't go into detail. I will point out that you can't (as yet) run VMware server under a XEN kernel (not sure why that would be needed anyway) so if you install with XEN, you need to install and switch the boot to the regular kernel, alternately don't install XEN during the installation process.

If XEN is installed as the kernel, you can switch to the normal kernel by installing the kernel package (an easy way):

yum install kernel.x86_64

You can change the default boot in Grub by editing:


To change the default to the non XEN kernel.


Installing VMWare 2 beta 2

I'd previously gone through this process with the first beta and it caused some issues, however most of these have been addressed in beta 2, which is looking quite good now.

A good guide to installing VMware server 2 can be found here:

and I used this as the basic process without much of a problem.

Note that in this beta you can't mount a CD ROM drive directly, what you can do it mount an ISO image of a disk by configuring it as a Datastore in VMware and then adding it as hardware to the VMware virtual machine.


Installing Solaris 10 (under VMware server 2)

IMPORTANT: Solaris using UFS is not as flexible as you might expect when it comes to resizing disks, so I'd strongly recommend allocating a generous amount of disk space for a Solaris disk when you start (>30Gb). While you can add disk space, by mounting space and 'growing' the file system with growfs, you can not do this at the root level.

Handy info:

Installing Solaris SBD (secure by default - a good policy!) means some things might need adjusment to enable them to work:

To enable X11 TCP listening, you need to set the property accordingly:

svccfg -s svc:/application/x11/x11-server setprop options/tcp_listen = true

Fixing XDMCP logins via Xnest:

By default the udpPort for cde_login is set to 0 which disables it!

Here is a good article on how to put that right:

basically, here's what you need to do:

svccfg -s cde-login setprop dtlogin/args=\"\"
svcadm restart cde-login

A good FAQ for SXDE:

including a useful info for adding additional disks:


Service control, some simple examples:

svcs -xv ssh
svcadm enable ssh
svcadm clear [service] // clear a service in maintenance mode