Java

Teaching Java How to Commit Suicide

At $work, we have a lot of java processes that are ran via cron and other wrappers that do some pretty critical tasks. The apps have been written so that the whole thing is wrapped in a try/catch that will call system.exit(1) should something not go right. Our wrapper scripts watch for a non-zero exit code, and alert Nagios if something went wrong.

This works great except for when a VM encounters an outOfMemory exception (OOM). The Java VM attempts to continue on, but if the main thread hits this exception, the entire VM will exit. However, the application code that exits with a status of 1 never gets called, so the application ends up dying with a status of 0. Well, Sun (Oracle now I guess) gave us a new option in Java 6 that was backported to 1.4.2_12 and up that allows us to tell Java to run a shell command when it encounters an OOM exception. By adding the option

-XX:OnOutOfMemoryError="kill -9 %p"

to our Java command line, the VM will execute a shell that calls the kill command, with an argument of the PID of the VM. The -9 option to kill will cause the VM to exit with a non-zero status, so that our wrappers will pick up the error and alert the right people.

Note: this feature was never backported to Java5 - sorry!

0
Your rating: None

Hudson > (CruiseControl * 2)

CruiseControl and I have never really gotten along.  When you're a Java shop, you have to use continuous integration. In fact, if you're a code shop, you need CI. For the longest time, CruiseControl was the only kid on the block.  I'd heard about Hudson quite a bit, but I didn't take the time to try it.  Why not?  Well, because CI is hard, and it takes forever to get setup right -- I didn't want to have to re-invest all that time.  Man, if only I'd known how wrong I was.

0
Your rating: None

Profile your Java GC Performance with GChisto

I stumbled across GChisto the other day when looking for some garbage collection analysis tools for Java. Anyone who's tried tuning Java GC (especially on older JVM's) knows that it's about as much fun as watching paint dry. However, many times you can seriously improve performance by taking the time to analyze what your GC's are doing. GChisto attempts to give you a birds-eye graphical view of your GC operations, and has a very handy comparison feature that allows you to compare the differences between GC logs.

0
Your rating: None

Profiling your Java 1.4.2 memory heap

New Java 6 devs and admins get all the fun. New toys, better performance, more auto-tuning -- yet you get stuck supporting a legacy java app that you can't upgrade past 1.4.2. Well, provided you have a more recent 1.4.2 JDK, you can use jhat too!

0
Your rating: None
Syndicate content