< prev index next >

test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 105              * don't *accidentally* inherit it when making the unreferenced()
 106              * callback.
 107              */
 108             UnicastRemoteObject.exportObject(obj);
 109             UnicastRemoteObject.unexportObject(obj, true);
 110 
 111             /*
 112              * Now create special context class loader before exporting the
 113              * remote object for real, so that it should be set when the
 114              * object's unreferenced() method is called.
 115              */
 116             ClassLoader intendedContext = new URLClassLoader(new URL[0]);
 117             Thread.currentThread().setContextClassLoader(intendedContext);
 118             System.err.println(
 119                 "created and set intended context class loader: " +
 120                 intendedContext);
 121 
 122             UnicastRemoteObject.exportObject(obj);
 123             System.err.println("exported remote object");
 124 
 125             Registry registry1 = TestLibrary.createRegistryOnUnusedPort();
 126             int port = TestLibrary.getRegistryPort(registry1);
 127             System.err.println("created registry");
 128 
 129             Registry registry = LocateRegistry.getRegistry("", port);
 130             registry.bind(BINDING, obj);
 131             System.err.println("bound remote object in registry");
 132 
 133             synchronized (obj.lock) {
 134                 registry.unbind(BINDING);
 135                 System.err.println("unbound remote object from registry; " +
 136                     "waiting for unreferenced() callback...");
 137                 /*
 138                  * This incantation seems sufficient to work around the
 139                  * ramifications of 4164696, so that this test will actually
 140                  * prove something useful about 1.2Beta4 or 1.2FCS before
 141                  * 4171278 was fixed.
 142                  */
 143                 for (int i = 0; i < 10; i++) {
 144                     System.gc();
 145                     obj.lock.wait(TIMEOUT / 10);


   1 /*
   2  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 105              * don't *accidentally* inherit it when making the unreferenced()
 106              * callback.
 107              */
 108             UnicastRemoteObject.exportObject(obj);
 109             UnicastRemoteObject.unexportObject(obj, true);
 110 
 111             /*
 112              * Now create special context class loader before exporting the
 113              * remote object for real, so that it should be set when the
 114              * object's unreferenced() method is called.
 115              */
 116             ClassLoader intendedContext = new URLClassLoader(new URL[0]);
 117             Thread.currentThread().setContextClassLoader(intendedContext);
 118             System.err.println(
 119                 "created and set intended context class loader: " +
 120                 intendedContext);
 121 
 122             UnicastRemoteObject.exportObject(obj);
 123             System.err.println("exported remote object");
 124 
 125             Registry registry1 = TestLibrary.createRegistryOnEphemeralPort();
 126             int port = TestLibrary.getRegistryPort(registry1);
 127             System.err.println("created registry");
 128 
 129             Registry registry = LocateRegistry.getRegistry("", port);
 130             registry.bind(BINDING, obj);
 131             System.err.println("bound remote object in registry");
 132 
 133             synchronized (obj.lock) {
 134                 registry.unbind(BINDING);
 135                 System.err.println("unbound remote object from registry; " +
 136                     "waiting for unreferenced() callback...");
 137                 /*
 138                  * This incantation seems sufficient to work around the
 139                  * ramifications of 4164696, so that this test will actually
 140                  * prove something useful about 1.2Beta4 or 1.2FCS before
 141                  * 4171278 was fixed.
 142                  */
 143                 for (int i = 0; i < 10; i++) {
 144                     System.gc();
 145                     obj.lock.wait(TIMEOUT / 10);


< prev index next >