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

      CodeSOD: Functionally, a Date

      September 16, 2025

      Creating Elastic And Bounce Effects With Expressive Animator

      September 16, 2025

      Microsoft shares Insiders preview of Visual Studio 2026

      September 16, 2025

      From Data To Decisions: UX Strategies For Real-Time Dashboards

      September 13, 2025

      DistroWatch Weekly, Issue 1139

      September 14, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 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

      Can I use React Server Components (RSCs) today?

      September 16, 2025
      Recent

      Can I use React Server Components (RSCs) today?

      September 16, 2025

      Perficient Named among Notable Providers in Forrester’s Q3 2025 Commerce Services Landscape

      September 16, 2025

      Sarah McDowell Helps Clients Build a Strong AI Foundation Through Salesforce

      September 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      I Ran Local LLMs on My Android Phone

      September 16, 2025
      Recent

      I Ran Local LLMs on My Android Phone

      September 16, 2025

      DistroWatch Weekly, Issue 1139

      September 14, 2025

      sudo vs sudo-rs: What You Need to Know About the Rust Takeover of Classic Sudo Command

      September 14, 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.

            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">startTraffic</span><span class="hljs-params">()</span>
            {
                Configuration.instance.inititiateStatistics();
                Statistics.instance.addStatisticListener(gui);
               
                <span class="hljs-keyword">if</span> (t != <span class="hljs-literal">null</span>)
                {
                    <span class="hljs-keyword">if</span> (t.isAlive())
                    {
                        t.destroy();
                    }
                }
               
                t = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Thread</span>(<span class="hljs-built_in">this</span>);
                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:

            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">run</span><span class="hljs-params">()</span>
            {
                <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>)
                {
                    <span class="hljs-keyword">try</span>
                    {
                        loaderMain.startTraffic();
                        <span class="hljs-keyword">break</span>;
                    }
                    <span class="hljs-keyword">catch</span> (Exception e)
                    {
                        System.out.println(<span class="hljs-string">"Exception in main loader thread!"</span>);
                        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

    DistroWatch Weekly, Issue 1139

    September 14, 2025
    News & Updates

    Building personal apps with open source and AI

    September 12, 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

    CAINE – live Linux distribution for digital forensics

    Linux

    CVE-2024-13427 – WordPress Pagelayer Stored Cross-Site Scripting

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-53019 – Cisco RTP Information Disclosure Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-9391 – Bjskzy Zhiyou ERP SQL Injection

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Development

    Code Review Best Practices for Automation Testing

    May 28, 2025

    Automation testing has revolutionized the way software teams deliver high-quality applications. By automating repetitive and critical test scenarios, QA teams achieve faster release cycles, fewer manual errors, and greater test coverage. But as these automation frameworks scale, so does the risk of accumulating technical debt in the form of flaky tests, poor structure, and inconsistent
    The post Code Review Best Practices for Automation Testing appeared first on Codoid.

    Apple Intelligence delay: A clash of two architectures and trivial AI features fell short of standards and expectations

    June 11, 2025

    FOSS Weekly #25.26: Torvalds-Gates Showdown, Hyprland Premium, Fedora’s 32-bit Debacle, Xfce Themes and More Linux Stuff

    June 26, 2025

    VS klaagt verdachte aan voor ransomware-aanvallen tegen Exchange-servers

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

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