A Practical Guide to Python Multithreading
target: specifies the function the thread will execute
args: positional arguments passed to the target function (tuple)
kwargs: keyword arguments passed to the target function (dictionary)
name: gives the thread a name
Thread object methods:
start()
join()
run(): the task function is ultimately executed inside the thread's run method
import ...
Posted on Sun, 17 May 2026 18:55:12 +0000 by les4017
Managing QThread References to Avoid Runtime Crashes in PyQt5
When integrating background processing into a PyQt5 application, instantiating QThread inside a local scope—such as a button-click handler—often triggers intermittent crashes or segmentation faults. The underlying cause is Python’s garbage collector reclaiming the QThread wrapper object once the local variable goes out of scope, even though the ...
Posted on Sun, 17 May 2026 07:59:24 +0000 by hessodreamy
Understanding Java Threads: From Basics to Synchronization
Threads are the smallest unit of execution within a process. A process itself is a running instance of a program—when you launch QQ.exe, the static file on disk becomes a dynamic process in memory. Inside that process, threads are the individual paths of execution that share the same address space.
Visualizing Two Threads
public class DualOutpu ...
Posted on Sat, 16 May 2026 05:00:09 +0000 by scheda
Common Lock Strategies and Synchronized Implementation
Common Lock Strategies
Detailed Lock Strategies
1. Pessimistic Lock vs. Optimistic Lock
Criteria: When locking, predict whether the probability of lock contention is high or low.
If the probability is predicted to be high, more work is required, and locking overhead (time, system resources) is larger → Pessimistic Lock
If the probability is pr ...
Posted on Sat, 16 May 2026 00:15:43 +0000 by elenev
Python ThreadPoolExecutor for Concurrent Task Execution
Overview
ThreadPoolExecutor from the concurrent.futures module provides a simple way to run multiple tasks concurrently in Python. It manages a pool of worker threads and distributes tasks across them efficiently.
Three-Step Pattern
# Step 1: Import the executor
from concurrent.futures import ThreadPoolExecutor
# Step 2: Create an executor ins ...
Posted on Thu, 14 May 2026 09:11:54 +0000 by cdherold
Comparing Synchronized and ReentrantLock in Java
Syntax and Application
The synchronized keyword integrates directly into the Java language syntax, applicable to entire methods or specific code boundaries. Conversely, ReentrantLock operates as a concrete class within the java.util.concurrent.locks package, demanding object instantiation and explicit invocations of lock() and unlock().
Lock L ...
Posted on Thu, 14 May 2026 04:29:21 +0000 by Iklekid
Using Java Multithreading to Replace Traditional For Loops
Implementation Workflow
This approach replaces sequential for loop execution with parallel task processing via a thread pool, reducing total runtime for CPU or I/O bound workloads.
Step 1: Confgiure the Thread Pool
First, create a managed thread pool to control concurrent thread usage. Avoid unbounded thread creasion to prevent resource exhaust ...
Posted on Thu, 14 May 2026 02:47:40 +0000 by runawaykinms
Understanding Thread Lifecycle and Control in Java
Threads in Java have a lifecycle consisting of seven states: New, Runnable, Running, Waiting, Sleeping, Blocked, and Dead.
Thread Sleep Mechanism
Example: Creating a SleepMethodTest class that extends JFrame to draw colored lines with random colors.
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class SleepMethodTest ext ...
Posted on Thu, 14 May 2026 02:00:02 +0000 by MiCR0
Understanding Java Thread Interruption: interrupt(), isInterrupted(), and interrupted()
Java's thread interruption mechanism relies on three distinct methods: interrupt(), isInterrupted(), and interrupted(). These methods operate around a boolean interruption flag maintained within each thread, but differ significantly in functionality and usage.
The Interruption Flag
Every Java thread maintains an internal interrupsion flag:
Set ...
Posted on Wed, 13 May 2026 21:26:20 +0000 by mospeed
The Pitfalls of Using Integer Objects as Lock Monitors in Java
This article delves into a common synchronization pitfall when using Integer objects as monitors in Java's synchronized blocks, particularly in concurrent scenarios.
Consider the following code simulating a ticket purchasing process with two threads:
import java.util.concurrent.TimeUnit;
public class SynchronizedTest {
public static void ...
Posted on Wed, 13 May 2026 20:59:39 +0000 by trinitywave