Skip to content

[Concurrent] Crowded Road - Executors.newFixedThreadPool #93

@fengyuanyang

Description

@fengyuanyang

Description
Provide a ThreadPool that can allow only specific number of cars to get through at once.
ExecutorService

Scenario
The traffic is pretty bad and crowded, only limited number cars can get through

Given 2 parameters for method A(int allowCars, int totalCars)
And one AtomicInteger variable(B) to increase/decrease the number of cars  
And one variable maxCars(C) to record the max(B)
When allowCars = 2, and totalCars = 10
Expect maxCars  = 2

When allowCars = 3, and totalCars = 20
Expect maxCars  = 3

When allowCars = 1, and totalCars = 1
Expect maxCars  = 1

Additional context

Add any other context, links references or screenshots about the feature request here.

Important Checklist

  • I have written unit test first, make it red(fail first).
  • I have then written logic code, make it green(success)
  • I have tried to refactor my code, make it understandable(document my code)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions