Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      What I Wish Someone Told Me When I Was Getting Into ARIA

      June 17, 2025

      SD Times 100

      June 17, 2025

      Managing the growing risk profile of agentic AI and MCP in the enterprise

      June 17, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 16, 2025

      Funny Windows 11 bug brings back classic Windows boot sound from 20 years ago

      June 17, 2025

      Windows 11 news and updates in June: Microsoft’s AI agent in Settings makes adjusting your PC easier than ever

      June 17, 2025

      uBlock Origin ships to Edge for Android as Google kills it on Chrome

      June 17, 2025

      Windows Hello face unlock no longer works in the dark, and Microsoft says it’s not a bug

      June 17, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Community News: Latest PECL Releases (06.17.2025)

      June 17, 2025
      Recent

      Community News: Latest PECL Releases (06.17.2025)

      June 17, 2025

      Stream-Omni: Simultaneous Multimodal Interactions with Large Language-Vision-Speech Model

      June 17, 2025

      How Inclusive Design Leading and Creating Solutions for Universal Design

      June 17, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Funny Windows 11 bug brings back classic Windows boot sound from 20 years ago

      June 17, 2025
      Recent

      Funny Windows 11 bug brings back classic Windows boot sound from 20 years ago

      June 17, 2025

      Windows 11 news and updates in June: Microsoft’s AI agent in Settings makes adjusting your PC easier than ever

      June 17, 2025

      uBlock Origin ships to Edge for Android as Google kills it on Chrome

      June 17, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Pulling at the Start of a Thread

    CodeSOD: Pulling at the Start of a Thread

    May 1, 2025

    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 are better abstractions around threads that would avoid the need to manage thread instances directly. I certainly don’t love situations where a Runnable also manages its own thread instance.

    This is almost certainly a race condition, but I don’t know if this function is called from multiple threads (but I suspect it might be).

    But what’s more interesting is where this code gets called. You see, starting a thread could trigger an exception, so you need to handle that:

            public void run()
            {
                while (true)
                {
                    try
                    {
                        loaderMain.startTraffic();
                        break;
                    }
                    catch (Exception e)
                    {
                        System.out.println("Exception in main loader thread!");
                        e.printStackTrace();
                    }
                }
            }
    

    Inside of an infinite loop, we try to start traffic. If we succeed, we break out of the loop. If we fail, well, we try and try again and again and again and again and again and again…

    Jonas writes:

    Since I’m the only one that dares to wade through the opaque mess of code that somehow, against all odds, manages to work most of the time, I get to fix it whenever it presents strange behavior.

    I suspect it’s going to present much more strange behavior in the future.

    [Advertisement]
    ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.18: Linux Magazine, Modern Terminals, Muse Pi, apt Guide and More
    Next Article Linux Schools – Ubuntu-based server based distribution

    Related Posts

    News & Updates

    Funny Windows 11 bug brings back classic Windows boot sound from 20 years ago

    June 17, 2025
    News & Updates

    Windows 11 news and updates in June: Microsoft’s AI agent in Settings makes adjusting your PC easier than ever

    June 17, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    How to Change the Password of a Superuser in Django

    Development

    CVE-2025-46052 – WebERP SQL Injection

    Common Vulnerabilities and Exposures (CVEs)

    Slay in style with RTX 50-series DOOM: The Dark Ages PCs, laptops, and GPUs you could get free — act fast before the giveaways end

    News & Updates

    Best Tools To Lower Ping And Lag In Online Games [2025 tested]

    Operating Systems

    Highlights

    News & Updates

    “I wish everybody could play my game.” The Outer Worlds 2 director doesn’t like its $80 price tag either, and says it was an Xbox decision

    June 12, 2025

    The first Xbox game to cost $80 is The Outer Worlds 2, but its director…

    CVE-2025-47102 – Adobe Experience Manager DOM-based Cross-Site Scripting (XSS)

    June 10, 2025

    BSD Release: FreeBSD 14.3

    June 9, 2025

    CVE-2025-45797 – TOTOlink A950RG Buffer Overflow Vulnerability in NoticeUrl Parameter

    May 8, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.