Article 1NR1C CodeSOD: Exit Thread

CodeSOD: Exit Thread

by
Remy Porter
from The Daily WTF on (#1NR1C)

Objects left in the garage or the attic tend to multiply. If you don't clean them regularly, you find mysterious and inexplicable things have bred like rabbits. "Why is there a bag of marbles in this box, and when did I ever buy an ugly Christmas sweater?"

Without regular refactoring, the same thing can happen to your code-base. Michal is finally taking a look at a bit of code that hasn't been touched since 2001. The original developer has left the company, there's no documentation, and the SVN history has long since been discarded.

This leaves Michal with many questions. For example- why did the original developer pepper the code with dozens of calls to System.exit(0)? While that's one way to end a Java program, it's not the sort of thing you tend to scatter through the code-base like rice at a wedding. Even worse, though, the calls looked like this:

 if(stopRequested){ Thread terminationThread = new Thread(new Runnable() { @Override public void run() { System.exit(0); } }); terminationThread.start(); }

No one knows why this runs in a separate thread. It certainly doesn't need to- a call to System.exit terminates the JVM, along with all the threads in it.

proget-icon.png [Advertisement] High availability, Load-balanced or Basic - design your own Universal Package Manager, allow the enterprise to scale as you grow. Download and see for yourself! TheDailyWtf?d=yIl2AUoC8zA-QChUH4r65Q
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments