Never mind, I see at least one reason why my last post would be incorrect. The length variable could be set out-of-order before all of the factorials up to length are calculated. Is there any simple way to write this function so it's thread-safe without using synchronized just to access cached results?