Thread-safe counter (synchronized)
Java
Hard
6 views
Problem Description
Task: implement a Counter class with increment and get methods thread-safe using synchronized.
Output Format
Return value
Constraints
No atomic classes needed.
Official Solution
static class Counter{private int v; synchronized void inc(){v++;} synchronized int get(){return v;}}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!