Why StackOverflow? Supporting tagline
Recently I've found myself getting into StackOverflow in a big way. There are two different types of StackOverflow users, those who use it for an easy answer to their less simple programming problems, and those who indulge the first type by answering.
Having leeched the StackOverflow community for the first three years of my degree I decided it was time to give something back. This was the single best self development decision I have ever made.
I have learned more from answering SO questions over the last few weeks than I've learned in the last few years of my degree. As an example, here's a question from the other day that I answered. The original question (found here) was this:
blog comments powered by Disqus
I have a task in which I have to read data using different threads. The problem is that due to the limitation of read rates, I built different threads with thread groups. Can any one tell me how to sleep one entire thread group so that it begins execution from exact same place where it left and the other thread groups remain executing?Not a very normal problem, obviously Threads should not be controlled like this. However, trying to be helpful I hastily answered:
Is it enough to enumerate the Thread group and call sleep on each thread?That sounds simple enough. However, had I thought about it for more than a minute I would have realised a debilitating flaw, which was instantly pointed out to me by the comment:// initialise the ThreadGroup with Threads ThreadGroup tg; // initialize an Array to hold enumerated Threads Thread[] threadsToSleep = new Thread[count]; // Copy thread references into array tg.enumerate(threadsToSleep); // Sleep each thread for specified time for (Thread t : threadsToSleep { t.sleep(sleepTime) }
Sleep is a static method. You will sleep the current thread and not the thread you're iterating on – John VintDuh. Of course Thread.sleep() is Static and my answer is useless. My idiocy aside, the point I'm trying to make is that my quick humiliation on this question means I will never forget my mistake. I need not point out the usefulness of this. It's even suggested that high StackOverflow reputation will help you stand out to employers and is a great thing to include on your resume. So what are you waiting for? Start answering questions too!
blog comments powered by Disqus
Published
15 February 2012