MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test.MyLoadUnloadTest Class Reference
Collaboration diagram for test.MyLoadUnloadTest:

Classes

class  FilterClassLoader
class  MyURLClassLoader
class  SelfishFileClassLoader

Static Public Member Functions

static void test0 () throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, MalformedURLException, InstantiationException
static void test () throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, MalformedURLException, InstantiationException
static void main (String[] args) throws Exception

Static Protected Attributes

static final PrintWriter out = new PrintWriter(System.out, true)
static final PrintWriter err = new PrintWriter(System.err, true)
static WeakReference< ClassLoader > cl = null

Detailed Description

A test for loading, calling into, and unloading a native library.

Under the JNI specification, a native library is loaded by the class loader of that class which called the method System.loadLibrary(String). In a Java VM, a library cannot be loaded into more than one class loader (since JDK 1.2, to preserve the separation of name-spaces). A library is unloaded when the class loader containing the library is garbage collected.

Therefore, the task of loading of the native library has to be carried out by newly created class loader instances that are separate from the loader of this test class. This implies that this test class must not statically refer to the code calling into the native library, for this would load the native library by this class loader when running this test, and any subsequent attempt to load the library by another class loader instance would fail (with an UnsatisfiedLinkError).

Hence, this class tests the loading and unloading of a native library by executing the following cycle at least twice:

  1. create a test class loader instance,
  2. using reflection, instruct the test class loader to load the a native library and run Java code calling into the native library,
  3. clear any (strong) references to the test class loader
  4. invoke the system's garbage collector to finalize the test class loader and unload the library.

Definition at line 72 of file MyLoadUnloadTest.java.

Member Data Documentation

WeakReference<ClassLoader> test.MyLoadUnloadTest.cl = null
staticprotected

A weak reference to a class loader loading the native library.

Definition at line 103 of file MyLoadUnloadTest.java.

final PrintWriter test.MyLoadUnloadTest.err = new PrintWriter(System.err, true)
staticprotected

The stream to write error messages to.

Definition at line 82 of file MyLoadUnloadTest.java.

final PrintWriter test.MyLoadUnloadTest.out = new PrintWriter(System.out, true)
staticprotected

The stream to write messages to.

Definition at line 77 of file MyLoadUnloadTest.java.


The documentation for this class was generated from the following file: