TGViewer
Programming Quiz Channel Programming Quiz Channel @programming_quizz · 797 subscribers
Post #525 115
Topic: Java

🔍 Quick look before the question:

public class Test {
static int counter = 0;

static synchronized void increment() {
counter++;
}

public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
for (int i = 0; i < 1000; i++) increment();
});
Thread t2 = new Thread(() -> {
for (int i = 0; i < 1000; i++) increment();
});
t1.start(); t2.start();
t1.join(); t2.join();
System.out.println(counter);
}
}
More from @programming_quizz
  1. Oct 12, 2026Post #571
  2. Oct 10, 2026Post #570
  3. Oct 8, 2026Post #569
  4. Oct 6, 2026Post #568
  5. Oct 4, 2026Post #567
  6. Oct 3, 2026Post #566
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →