GlassFish tips for demoers and others (avoid those restarts)

One of the good things about having your environment change is that it makes you ask yourself the question of why you ended up with some habits. NetBeans 6.0 Milestone 9 not bundling Tomcat by default (but still supporting it) is one such example I think. On that note I’d invite you to read Geertjan’s post on Oddly Shaped Bicycles.

So the above thread got the discussion going about NetBeans experiences with people using GlassFish as part of their demos whether it is to demo Java EE 5 features, deploy and run OpenESB artifacts, run OpenPortal, an interoperable JAX-WS Web Service, or a JRuby on Rails application, a whole lot of people use GlassFish nowadays. Whether using Tomcat or GlassFish a seamless experience can be achieved with fast startups or incremental deployments.

Startup time for GlassFish is not perfect (we’re working on it) but very good for a full-blown application server. Luckily, incremental deployment is most often extremely fast and, if no restart is required which makes the life of demoers but also pretty much everyone else’s so much more enjoyable (having an unplanned application server restart during a demo is never good).

So here’s a little list of do’s and dont’s when using GlassFish in demos (not your typical use-case but still…). If this looks too long, skip to the last bullet.

  • Use GlassFish v2. First of all if you’re using GlassFish v1, this version was pretty much frozen more than a year ago. GlassFish v2 has much better startup time, better error handling, and less restarts (almost everything in the web container is now dynamic). GlassFish v2 is now in beta 2, so if you’re using a NetBeans milestone, you really shouldn’t be afraid to use a GlassFish beta! :)

  • Delete does not undeploy. One of the most annoying problem reported is application server restarts. With GlassFish v1, this clearly happens when there is a mismatch between you domain.xml (in domains/domain1/) and the file system and this is most likely due to deleting projects from NetBeans (after you’re done with the previous demo) and not undeploying them (I filed this RFE).

  • Undeploy only works on existing projets. When using the web UI to undeploy non-existing applications, you get a (what could be a bit friendlier) error/exception. All it says it that it couldn’t find the application (most likely a DPL5040). When using the GlassFish web UI, make sure you pay attention to the upper right corner which will tell you (“Restart Required”) a restart is needed (and subsequent deployments from NetBeans will trigger a restart if you don’t do it yourself before).

  • Hand cleaning. If you don’t want to start the AS to clean older applications to then restart it, you can always be careful and remove the appropriate entries in domain.xml (not sure I should be suggesting this). Only make sure you keep an backup of domain.xml and run a asadmin verify-domain-xml to make sure you have a valid config file.

  • Clean, then restart. Always (re)start your application server before the demo only after any conflicts between domain.xml and the filesystem have been resolved (see above).

  • Clean or remove the log file. When Starting GlassFish from NetBeans, the log file of the application server is shown in the IDE. If it’s big it’ll take (what can seem) forever to ‘cat’ thru before actually showing the start-up sequence. You should probably delete the glassfish logfile (domains/domain/logs/server.log) or have the log file rotate with on a small size (a few hundred Kb).

  • Restart from scratch? I’ve you want to be really extra safe, you can re-create the domain using:
% asadmin delete-domain domain_name
% asadmin create-domain domain_name

(be careful, this creates a brand new domain with no resources other than the default ones)

  • Backup/Restore! Probably a better alternative (one that could make most of the above obsolete) is to do domain backup/restore:
% asadmin backup-domain domain_name
% asadmin restore-domain [--filename backup_file] domain_name

(make sure the domain is stopped and in the desired stable state when creating the backup).

If you have reproducible use-cases of an annoying/unneeded application server restart with GlassFish v2, please report it (bug, or comment here).

Feel free to suggest tips. I’m sure I’m missing a few.

Author: alexismp

Google Developer Relations in Paris.

One thought on “GlassFish tips for demoers and others (avoid those restarts)”

Comments are closed.

%d bloggers like this: