Category: Uncategorized
-
Cocurrency Problem
Concurrency problems happen when multiple threads access shared resources simultaneously, leading to unpredictable or incorrect results. Common Concurrency Problems: Race Conditions Deadlocks Livelocks Starvation Memory Consistency Errors Ways to Solve Concurrency Problems Locks (synchronized, Lock interface) Atomic Variables Volatile Keyword Immutable Objects Thread-safe Collections Executor Framework Fork/Join Framework Thread-local Storage Summary Method Handles Race? Handles…
-
External Configuration Pattern
The External Configuration pattern separates application configuration (e.g., credentials, URLs, environment settings) from application code. Why Use It? Benefit Reason Environment flexibility Deploy same app to dev, staging, prod with different configs Security Keep secrets out of source code Dynamic updates Change config at runtime without restarting apps CI/CD friendly Promote the same artifact across…
-
Service Discovery Pattern
Service Discovery enables services to register themselves and discover other services dynamically, removing the need to hardcode IPs/ports/URLs. Two Roles: When to Use It You need Service Discovery when: Situation Why You Need It Services scale dynamically Their IPs/ports change frequently You deploy in cloud/Kubernetes Pods and containers are ephemeral You want resilience + flexibility…
-
Circuit Breaker Pattern
What is the Circuit Breaker Pattern? A Circuit Breaker monitors for failures and short-circuits calls to a downstream service if it detects that the service is failing repeatedly. This avoids: It works like an electrical circuit breaker: State Description Closed Everything is normal. Calls pass through. Failures are counted. Open Too many failures. Calls are…
-
Java Thread
Basic way to create a thread Life cycle Joining Threads Joining threads is a mechanism that allows one thread to wait for the completion of another thread before it continues its execution. When a thread invokes the join() method on another thread, it will pause its execution until the other thread completes (terminates). The join()…