samples/reentrant/src/org/apidesign/reentrant/CriticalSectionSynchronized.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:54:36 +0200
changeset 111 3905a2e66b9b
permissions -rw-r--r--
Sample code with various attempts to fight with reentrant code
     1 package org.apidesign.reentrant;
     2 
     3 import java.util.Collection;
     4 
     5 public class CriticalSectionSynchronized<T extends Comparable<T>> implements CriticalSection<T> {
     6     private T pilot;
     7     private int cnt;
     8     
     9     public synchronized void assignPilot(T pilot) {
    10         this.pilot = pilot;
    11     }
    12 
    13     public int sumBigger(Collection<T> args) {
    14         for (T cmp : args) {
    15             if (pilot.compareTo(cmp) < 0) {
    16                 cnt++;
    17             }
    18         }
    19         return cnt;
    20     }
    21 
    22     public int getCount() {
    23         return cnt;
    24     }
    25 }