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
     1 package org.apidesign.javamonitorflaws;
     2 
     3 import java.beans.PropertyChangeListener;
     4 import java.beans.PropertyChangeSupport;
     5 
     6 /**
     7  *
     8  * @author Jaroslav Tulach <jtulach@netbeans.org>
     9  */
    10 // BEGIN: monitor.pitfalls.subclass
    11 public class MultiplyCache extends Cache<String,Integer>
    12 implements CacheTest.CacheToTest {
    13     private PropertyChangeSupport pcs;
    14     private int multiply;
    15     public static final String PROP_MULTIPLY = "multiply";
    16 
    17     public synchronized int getMultiply() {
    18         return multiply;
    19     }
    20     public synchronized void setMultiply(int multiply) {
    21         int oldMultiply = this.multiply;
    22         this.multiply = multiply;
    23         pcs.firePropertyChange(PROP_MULTIPLY, oldMultiply, multiply);
    24     }
    25 
    26     public synchronized void addPropertyChangeListener(
    27         PropertyChangeListener listener
    28     ) {
    29         if (pcs == null) {
    30             pcs = new PropertyChangeSupport(this);
    31         }
    32         pcs.addPropertyChangeListener(listener);
    33     }
    34     public synchronized void removePropertyChangeListener(
    35         PropertyChangeListener listener
    36     ) {
    37         if (pcs != null) {
    38             pcs.removePropertyChangeListener(listener);
    39         }
    40     }
    41 
    42     @Override
    43     protected Integer createItem(String f) {
    44         return f.length() * multiply;
    45     }
    46 }
    47 // END: monitor.pitfalls.subclass
    48 
    49