[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-serviceability-dev
Subject:    Fwd: RFR(s): 8154801 deprecate java.util.Observable/Observer
From:       Stuart Marks <stuart.marks () oracle ! com>
Date:       2016-04-22 2:21:16
Message-ID: 57198A9C.3000104 () oracle ! com
[Download RAW message or body]

Hi all,

I just posted the following to core-libs-dev.

The only user of Observable/Observer in the JDK is the Serviceability Agent. 
Unless I missed something, the only impact the deprecation will have on SA is 
the generation of deprecation warnings, were SA to be compiled with deprecation 
warnings enabled. Currently, SA is compiled without warnings enabled.

I can assist with migrating SA away from Observable/Observer, if there's any 
interest in doing that.

s'marks


-------- Forwarded Message --------
Subject: RFR(s): 8154801 deprecate java.util.Observable/Observer
Date: Thu, 21 Apr 2016 19:17:12 -0700
From: Stuart Marks <stuart.marks@oracle.com>
To: core-libs-dev <core-libs-dev@openjdk.java.net>

Hi all,

Here's a small proposal to deprecate the java.util.Observable and Observer. This
deprecation will not be for removal.

See https://bugs.openjdk.java.net/browse/JDK-8154801 for some background.

Essentially, these classes are a very thin implementation of the Observer
pattern. These classes provide little beyond maintaining a list of callbacks
plus the ability calling them upon request. A 1999 comment from Josh Bloch in a
related bug report said that they are no longer under active development and
have been superseded by the 1.1 Beans/AWT event model.

Their only use in the JDK is in the Hotspot Serviceability Agent, which doesn't
even use Observable, and which uses Observer as a callback interface. SA's use
of Observer could easily be replaced with lambdas and Consumer<TypeDataBase>.

There is some use of these classes "in the wild" but only for conventional
callback purposes. Deprecation will generate warnings if that code is recompiled
with deprecation warnings enabled.

Diffs follow.

Thanks,

s'marks



diff -r 92280897299f -r e16d8d56da15
src/java.base/share/classes/java/util/Observable.java
--- a/src/java.base/share/classes/java/util/Observable.java	Mon Apr 18 14:10:14
2016 -0700
+++ b/src/java.base/share/classes/java/util/Observable.java	Thu Apr 21 15:48:23
2016 -0700
@@ -58,7 +58,19 @@
   * @see     java.util.Observer
   * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
   * @since   1.0
+ *
+ * @deprecated
+ * This class and the {@link Observer} interface have been deprecated.
+ * The event model supported by {@code Observer} and {@code Observable}
+ * is quite limited, the order of notifications delivered by
+ * {@code Observable} is unspecified, and state changes are not in
+ * one-for-one correspondence with notifications.
+ * For a richer event model, consider using the
+ * {@link java.beans} package.  For reliable and ordered
+ * messaging among threads, consider using one of the concurrent data
+ * structures in the {@link java.util.concurrent} package.
   */
+@Deprecated(since="9")
  public class Observable {
      private boolean changed = false;
      private Vector<Observer> obs;
diff -r 92280897299f -r e16d8d56da15
src/java.base/share/classes/java/util/Observer.java
--- a/src/java.base/share/classes/java/util/Observer.java	Mon Apr 18 14:10:14
2016 -0700
+++ b/src/java.base/share/classes/java/util/Observer.java	Thu Apr 21 15:48:23
2016 -0700
@@ -31,7 +31,12 @@
   * @author  Chris Warth
   * @see     java.util.Observable
   * @since   1.0
+ *
+ * @deprecated
+ * This interface has been deprecated. See the {@link Observable}
+ * class for further information.
   */
+@Deprecated(since="9")
  public interface Observer {
      /**
       * This method is called whenever the observed object is changed. An




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic