Home / Function/ register() — netty Function Reference

register() — netty Function Reference

Architecture documentation for the register() function in ObjectCleaner.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  e0d2f0f6_13c1_e3bf_5723_afb50e0244db["register()"]
  f13b11d8_c490_1490_6aa6_8adffebc235a["ObjectCleaner"]
  e0d2f0f6_13c1_e3bf_5723_afb50e0244db -->|defined in| f13b11d8_c490_1490_6aa6_8adffebc235a
  f13ad067_056c_8a6e_2a43_c29e66dc8058["AutomaticCleanerReference()"]
  e0d2f0f6_13c1_e3bf_5723_afb50e0244db -->|calls| f13ad067_056c_8a6e_2a43_c29e66dc8058
  style e0d2f0f6_13c1_e3bf_5723_afb50e0244db fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/ObjectCleaner.java lines 95–125

    public static void register(Object object, Runnable cleanupTask) {
        AutomaticCleanerReference reference = new AutomaticCleanerReference(object,
                ObjectUtil.checkNotNull(cleanupTask, "cleanupTask"));
        // Its important to add the reference to the LIVE_SET before we access CLEANER_RUNNING to ensure correct
        // behavior in multi-threaded environments.
        LIVE_SET.add(reference);

        // Check if there is already a cleaner running.
        if (CLEANER_RUNNING.compareAndSet(false, true)) {
            final Thread cleanupThread = new FastThreadLocalThread(CLEANER_TASK);
            cleanupThread.setPriority(Thread.MIN_PRIORITY);
            // Set to null to ensure we not create classloader leaks by holding a strong reference to the inherited
            // classloader.
            // See:
            // - https://github.com/netty/netty/issues/7290
            // - https://bugs.openjdk.java.net/browse/JDK-7008595
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
                @Override
                public Void run() {
                    cleanupThread.setContextClassLoader(null);
                    return null;
                }
            });
            cleanupThread.setName(CLEANER_THREAD_NAME);

            // Mark this as a daemon thread to ensure that we the JVM can exit if this is the only thread that is
            // running.
            cleanupThread.setDaemon(true);
            cleanupThread.start();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does register() do?
register() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/internal/ObjectCleaner.java.
Where is register() defined?
register() is defined in common/src/main/java/io/netty/util/internal/ObjectCleaner.java at line 95.
What does register() call?
register() calls 1 function(s): AutomaticCleanerReference.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free