iluwatar / iluwatar/java-design-patterns

Coarse-Grained Lock pattern

Open
#1,289 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

epic: pattern info: help wanted type: feature
Dominant language
Java
Stars
94.7k
Forks
27.4k
Avg merge
3d 4h
Merged PRs (30d)
10

Description

Description

The Coarse-Grained Lock design pattern is a concurrency control strategy where a single lock is used to protect a large portion of code or multiple related resources. This approach simplifies lock management by reducing the number of locks needed and minimizing the potential for deadlocks. However, it can reduce concurrency as the coarse-grained lock may force threads to wait even when they could safely proceed.

Main Elements of the Pattern:
  • Single Lock Mechanism: One lock protects a large code segment or multiple resources.
  • Simplicity: Easier to implement and manage compared to fine-grained locks.
  • Reduced Concurrency: May lead to lower parallelism as threads may be unnecessarily blocked.
Implementation Steps:
  1. Identify the critical section or related resources that require protection.
  2. Implement a single lock to guard the entire critical section or group of resources.
  3. Ensure that the lock is acquired at the beginning and released at the end of the critical section.

References

Acceptance Criteria

  1. Implement a Coarse-Grained Lock in a chosen example within the project.
  2. Ensure the implementation follows the contribution guidelines provided in the project repository.
  3. Include comprehensive unit tests demonstrating the effectiveness and correctness of the Coarse-Grained Lock implementation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the repository's contribution guidelines and examining existing design-pattern examples to choose an appropriate location for the pattern. Define the example and its concurrency behavior before implementing it, then add unit tests that demonstrate correctness and complete the acceptance criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.