CodeSOD: Pulling at the Start of a Thread

This post was originally published on this site

The Daily WTF

For testing networking systems, load simulators are useful: send a bunch of realistic looking traffic and see what happens as you increase the amount of sent traffic. These sorts of simulators often rely on being heavily multithreaded, since one computer can, if pushed, generate a lot of network traffic.

Thus, when Jonas inherited a heavily multithreaded system for simulating load, that wasn’t a surprise. The surprise was that the developer responsible for it didn’t really understand threading in Java. Probably in other languages too, but in this case, Java was what they were using.

public void startTraffic() { Configuration.instance.inititiateStatistics(); Statistics.instance.addStatisticListener(gui); if (t != null) { if (t.isAlive()) { t.destroy(); } } t = new Thread(this); t.start(); }

Look, this is not a good way to manage threads in Java. I don’t know if I’d call it a WTF, but it’s very much a “baby’s first threading” approach. There

To read the full article click on the 'post' link at the top.