import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.Condition; class Traad { public static void main(String[] args) { Task task = new Task(); Thread t1 = new Thread(task); Thread t2 = new Thread(task); t1.start(); t2.start(); } } class Task implements Runnable { int teller = 0; Lock laas = new ReentrantLock(); Condition erFerdig = laas.newCondition(); @Override public void run() { for (int i = 0; i < 10000; i++) { laas.lock(); try { teller++; } finally { laas.unlock(); } } System.out.println("Traaden er ferdig, teller er: " + teller); } }