Example usage for io.netty.util.concurrent FastThreadLocal removeAll

List of usage examples for io.netty.util.concurrent FastThreadLocal removeAll

Introduction

In this page you can find the example usage for io.netty.util.concurrent FastThreadLocal removeAll.

Prototype

public static void removeAll() 

Source Link

Document

Removes all FastThreadLocal variables bound to the current thread.

Usage

From source file:com.google.firebase.database.core.RepoManager.java

License:Apache License

public static void destroy(Context ctx) {
    try {//from w  w  w  .j  a  v a  2  s.c  o  m
        instance.destroyInternal(ctx);
    } finally {
        ctx.stop();
        // Clean up Netty thread locals, which will also clean up any dangling threadDeathWatcher
        // daemons. See https://github.com/netty/netty/issues/7310 for more context.
        FastThreadLocal.removeAll();
    }
}

From source file:com.kevinherron.GatewayHook.java

@Override
public void shutdown() {
    logger.info("shutdown()");

    try {//w ww  .jav  a  2  s . c o m
        eventLoop.shutdownGracefully().get();
    } catch (Throwable e) {
        logger.error("Error waiting for event loop shutdown: {}", e.getMessage(), e);
    }
    try {
        GlobalEventExecutor.INSTANCE.shutdownGracefully().get();
    } catch (Throwable e) {
        logger.error("Error waiting for GlobalEventExecutor shutdown: {}", e.getMessage(), e);
    }
    try {
        DefaultAddressResolverGroup.INSTANCE.close();
    } catch (Throwable e) {
        logger.error("Error closing DefaultAddressResolverGroup: {}", e.getMessage(), e);
    }
    InternalThreadLocalMap.destroy();
    FastThreadLocal.removeAll();
}

From source file:org.apache.cassandra.concurrent.NamedThreadFactory.java

License:Apache License

/**
 * Ensures that {@link FastThreadLocal#remove() FastThreadLocal.remove()} is called when the {@link Runnable#run()}
 * method of the given {@link Runnable} instance completes to ensure cleanup of {@link FastThreadLocal} instances.
 * This is especially important for direct byte buffers allocated locally for a thread.
 *///from  w ww. j av  a2s  . c  om
public static Runnable threadLocalDeallocator(Runnable r) {
    return () -> {
        try {
            r.run();
        } finally {
            FastThreadLocal.removeAll();
        }
    };
}

From source file:org.lanternpowered.server.util.ThreadHelper.java

License:MIT License

private static Thread newFastThreadLocalThread0(Consumer<Thread> runnable, @Nullable String name) {
    requireNonNull(runnable, "runnable");
    final Consumer<Thread> runnable1 = thread0 -> {
        try {// w ww . java2s  .  com
            runnable.accept(thread0);
        } finally {
            FastThreadLocal.removeAll();
        }
    };
    final Thread thread;
    if (name != null) {
        thread = new FastThreadLocalThread(name) {
            @Override
            public void run() {
                runnable1.accept(this);
            }
        };
    } else {
        thread = new FastThreadLocalThread() {
            @Override
            public void run() {
                runnable1.accept(this);
            }
        };
    }
    return thread;
}

From source file:org.superbiz.javaee.listeners.AppContextListener.java

License:Apache License

@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
    logger.info("Destroying application context: {}", servletContextEvent.getServletContext().getContextPath());
    try {//from w  w  w .  j a  v a2 s. c om
        logger.info("Shutting down AbandonedConnection");
        AbandonedConnectionCleanupThread.shutdown();
    } catch (Throwable t) {
        logger.error("Exception shutting down AbandonedConnection: {}", t);
    }

    // This manually deregisters JDBC driver, which prevents Tomcat 7 from
    // complaining about memory leaks
    Enumeration<Driver> drivers = java.sql.DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        java.sql.Driver driver = drivers.nextElement();
        logger.info("Deregistering JDBC driver: {}", driver);
        try {
            java.sql.DriverManager.deregisterDriver(driver);
        } catch (Throwable t) {
            logger.error("Exception deregistering drivers: {}", t);
        }
    }

    try {
        logger.info("Shutting down Redisson: {}", redisson.getConfig());
        redisson.shutdown();
    } catch (Exception e) {
        logger.error("Error shutting down Redisson: {}", e);
    }

    try {
        FastThreadLocal.removeAll();
        FastThreadLocal.destroy();
    } catch (Exception e) {
        logger.error("Fatal error: {}", e);
    }
}