import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.Lock; class Tell implements Runnable { Lock laas = new ReentrantLock(); final int MAXCOUNT = 500000000; public int fellesTeller = 0; @Override public void run() { int hallo = 0; for (int i = 0; i < MAXCOUNT; i++) { laas.lock(); try { if (++fellesTeller%100000000 == 0) { System.out.println("Hello for the " + ++hallo + "th time"); } } finally { laas.unlock(); } } System.out.println(fellesTeller); } public static void main(String[] args) { Runnable r = new Tell(); Thread t = new Thread(r); Thread t2 = new Thread(r); t.start(); t2.start(); } }