mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 03:54:33 +02:00
5026703: RFE: DOC: Are PropertyChangeSupport & VetoableChangeSupport Thread-Safe? --Docs Should Say
Reviewed-by: peterz, rupashka
This commit is contained in:
parent
803014e138
commit
fe4ebb456f
2 changed files with 78 additions and 4 deletions
|
@ -34,12 +34,49 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a utility class that can be used by beans that support bound
|
* This is a utility class that can be used by beans that support bound
|
||||||
* properties. You can use an instance of this class as a member field
|
* properties. It manages a list of listeners and dispatches
|
||||||
* of your bean and delegate various work to it.
|
* {@link PropertyChangeEvent}s to them. You can use an instance of this class
|
||||||
|
* as a member field of your bean and delegate these types of work to it.
|
||||||
|
* The {@link PropertyChangeListener} can be registered for all properties
|
||||||
|
* or for a property specified by name.
|
||||||
|
* <p>
|
||||||
|
* Here is an example of {@code PropertyChangeSupport} usage that follows
|
||||||
|
* the rules and recommendations laid out in the JavaBeans™ specification:
|
||||||
|
* <pre>
|
||||||
|
* public class MyBean {
|
||||||
|
* private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||||
*
|
*
|
||||||
|
* public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||||
|
* this.pcs.addPropertyChangeListener(listener);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||||
|
* this.pcs.removePropertyChangeListener(listener);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* private String value;
|
||||||
|
*
|
||||||
|
* public String getValue() {
|
||||||
|
* return this.value;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public void setValue(String newValue) {
|
||||||
|
* String oldValue = this.value;
|
||||||
|
* this.value = newValue;
|
||||||
|
* this.pcs.firePropertyChange("value", oldValue, newValue);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* [...]
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* A {@code PropertyChangeSupport} instance is thread-safe.
|
||||||
|
* <p>
|
||||||
* This class is serializable. When it is serialized it will save
|
* This class is serializable. When it is serialized it will save
|
||||||
* (and restore) any listeners that are themselves serializable. Any
|
* (and restore) any listeners that are themselves serializable. Any
|
||||||
* non-serializable listeners will be skipped during serialization.
|
* non-serializable listeners will be skipped during serialization.
|
||||||
|
*
|
||||||
|
* @see VetoableChangeSupport
|
||||||
*/
|
*/
|
||||||
public class PropertyChangeSupport implements Serializable {
|
public class PropertyChangeSupport implements Serializable {
|
||||||
private PropertyChangeListenerMap map = new PropertyChangeListenerMap();
|
private PropertyChangeListenerMap map = new PropertyChangeListenerMap();
|
||||||
|
|
|
@ -34,12 +34,49 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a utility class that can be used by beans that support constrained
|
* This is a utility class that can be used by beans that support constrained
|
||||||
* properties. You can use an instance of this class as a member field
|
* properties. It manages a list of listeners and dispatches
|
||||||
* of your bean and delegate various work to it.
|
* {@link PropertyChangeEvent}s to them. You can use an instance of this class
|
||||||
|
* as a member field of your bean and delegate these types of work to it.
|
||||||
|
* The {@link VetoableChangeListener} can be registered for all properties
|
||||||
|
* or for a property specified by name.
|
||||||
|
* <p>
|
||||||
|
* Here is an example of {@code VetoableChangeSupport} usage that follows
|
||||||
|
* the rules and recommendations laid out in the JavaBeans™ specification:
|
||||||
|
* <pre>
|
||||||
|
* public class MyBean {
|
||||||
|
* private final VetoableChangeSupport vcs = new VetoableChangeSupport(this);
|
||||||
*
|
*
|
||||||
|
* public void addVetoableChangeListener(VetoableChangeListener listener) {
|
||||||
|
* this.vcs.addVetoableChangeListener(listener);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public void removeVetoableChangeListener(VetoableChangeListener listener) {
|
||||||
|
* this.vcs.removeVetoableChangeListener(listener);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* private String value;
|
||||||
|
*
|
||||||
|
* public String getValue() {
|
||||||
|
* return this.value;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public void setValue(String newValue) throws PropertyVetoException {
|
||||||
|
* String oldValue = this.value;
|
||||||
|
* this.vcs.fireVetoableChange("value", oldValue, newValue);
|
||||||
|
* this.value = newValue;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* [...]
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* A {@code VetoableChangeSupport} instance is thread-safe.
|
||||||
|
* <p>
|
||||||
* This class is serializable. When it is serialized it will save
|
* This class is serializable. When it is serialized it will save
|
||||||
* (and restore) any listeners that are themselves serializable. Any
|
* (and restore) any listeners that are themselves serializable. Any
|
||||||
* non-serializable listeners will be skipped during serialization.
|
* non-serializable listeners will be skipped during serialization.
|
||||||
|
*
|
||||||
|
* @see PropertyChangeSupport
|
||||||
*/
|
*/
|
||||||
public class VetoableChangeSupport implements Serializable {
|
public class VetoableChangeSupport implements Serializable {
|
||||||
private VetoableChangeListenerMap map = new VetoableChangeListenerMap();
|
private VetoableChangeListenerMap map = new VetoableChangeListenerMap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue