title

fire chief's random developer tidbits

Thursday, June 7, 2012

Chicks dig ninja loop debugging skills

Let's say you have a long running process that is misbehaving and there are other more important processes in the same JVM.  You want to kill the misbehaving process because it is leaking memory (or whatever).  You can attach a debugger and see it looping through its job and find that it has a ton of work to do.  You want to stop it so other more important processes can get some processing time and some memory.  If the loop is a for each on a hashmap you can cause it to early exit by doing a couple things.  Here's how:

  1. find the hashmap's internal table object count: table.count
  2. in the i$ iterator object representing the for each, set the index to just below the table.count
  3. iterator will exit without ConcurrentModification or other errors
WARNING: don't do this unless you understand the process you are interrupting in a deep way and know that there are no side effects.