samples/deadlock/test/org/apidesign/javamonitorflaws/MultiplyCache.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
parent 318 38ebce3000fd
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
jtulach@315
     1
package org.apidesign.javamonitorflaws;
jtulach@315
     2
jtulach@315
     3
import java.beans.PropertyChangeListener;
jtulach@315
     4
import java.beans.PropertyChangeSupport;
jtulach@315
     5
jtulach@315
     6
/**
jtulach@315
     7
 *
jtulach@315
     8
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@315
     9
 */
jtulach@317
    10
// BEGIN: monitor.pitfalls.subclass
jtulach@319
    11
public class MultiplyCache extends Cache<String,Integer>
jtulach@319
    12
implements CacheTest.CacheToTest {
jtulach@315
    13
    private PropertyChangeSupport pcs;
jtulach@315
    14
    private int multiply;
jtulach@315
    15
    public static final String PROP_MULTIPLY = "multiply";
jtulach@315
    16
jtulach@315
    17
    public synchronized int getMultiply() {
jtulach@315
    18
        return multiply;
jtulach@315
    19
    }
jtulach@315
    20
    public synchronized void setMultiply(int multiply) {
jtulach@315
    21
        int oldMultiply = this.multiply;
jtulach@315
    22
        this.multiply = multiply;
jtulach@315
    23
        pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply);
jtulach@315
    24
    }
jtulach@315
    25
jtulach@318
    26
    public synchronized void addPropertyChangeListener(
jtulach@318
    27
        PropertyChangeListener listener
jtulach@318
    28
    ) {
jtulach@315
    29
        if (pcs == null) {
jtulach@315
    30
            pcs = new PropertyChangeSupport(this);
jtulach@315
    31
        }
jtulach@315
    32
        pcs.addPropertyChangeListener(listener);
jtulach@315
    33
    }
jtulach@318
    34
    public synchronized void removePropertyChangeListener(
jtulach@318
    35
        PropertyChangeListener listener
jtulach@318
    36
    ) {
jtulach@315
    37
        if (pcs != null) {
jtulach@315
    38
            pcs.removePropertyChangeListener(listener);
jtulach@315
    39
        }
jtulach@315
    40
    }
jtulach@315
    41
jtulach@315
    42
    @Override
jtulach@315
    43
    protected Integer createItem(String f) {
jtulach@319
    44
        return f.length() * multiply;
jtulach@315
    45
    }
jtulach@317
    46
}
jtulach@317
    47
// END: monitor.pitfalls.subclass
jtulach@315
    48
jtulach@315
    49