• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JreMemoryLeakPreventionListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.catalina.core.JreMemoryLeakPreventionListener的典型用法代码示例。如果您正苦于以下问题:Java JreMemoryLeakPreventionListener类的具体用法?Java JreMemoryLeakPreventionListener怎么用?Java JreMemoryLeakPreventionListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JreMemoryLeakPreventionListener类属于org.apache.catalina.core包,在下文中一共展示了JreMemoryLeakPreventionListener类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createTomcat

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
private static Tomcat createTomcat(int port, String contextPath, String docBase) throws ServletException {
    String tmpDir = System.getProperty("java.io.tmpdir");
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir(tmpDir);
    tomcat.getHost().setAppBase(tmpDir);
    tomcat.getHost().setAutoDeploy(false);
    tomcat.getEngine().setBackgroundProcessorDelay(-1);
    tomcat.setConnector(newNioConnector());
    tomcat.getConnector().setPort(port);
    tomcat.getService().addConnector(tomcat.getConnector());
    Context context = tomcat.addWebapp(contextPath, docBase);
    StandardServer server = (StandardServer) tomcat.getServer();
    server.addLifecycleListener(new AprLifecycleListener());
    server.addLifecycleListener(new JreMemoryLeakPreventionListener());
    return tomcat;
}
 
开发者ID:kevinKaiF,项目名称:cango,代码行数:17,代码来源:TomcatBootstrap.java


示例2: setUp

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();

    Tomcat tomcat = getTomcatInstance();

    // BZ 49218: The test fails if JreMemoryLeakPreventionListener is not
    // present. The listener affects the JVM, and thus not only the current,
    // but also the subsequent tests that are run in the same JVM. So it is
    // fair to add it in every test.
    tomcat.getServer().addLifecycleListener(
        new JreMemoryLeakPreventionListener());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:14,代码来源:TestVirtualContext.java


示例3: setUp

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();

    Tomcat tomcat = getTomcatInstance();

    // The test fails if JreMemoryLeakPreventionListener is not
    // present. The listener affects the JVM, and thus not only the current,
    // but also the subsequent tests that are run in the same JVM. So it is
    // fair to add it in every test.
    tomcat.getServer().addLifecycleListener(
            new JreMemoryLeakPreventionListener());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:14,代码来源:TestWarDirContext.java


示例4: newStandardServer

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Override
public TomcatHostBuilder newStandardServer(int port, File baseDir, int httpPort, int ajpPort) {
    ContextResource memoryDatabase = new ContextResource();
    memoryDatabase.setName("name");
    memoryDatabase.setDescription("desc");

    TomcatServerBuilder serverBuilder = newServer(port);
    if (baseDir != null) {
        serverBuilder.setCatalinaBase(baseDir);
        serverBuilder.setCatalinaHome(baseDir);
    }

    Map<String, String> connConfig = new HashMap<>();
    connConfig.put(Constants.EXECUTOR_NAME_ATTR, DEFAULT_EXECUTOR_NAME);

    return serverBuilder.enableNaming()
    			// .addLifecycleListener(SecurityListener.class)
    			.addLifecycleListener(AprLifecycleListener.class)
    			.addLifecycleListener(JreMemoryLeakPreventionListener.class)
    			.addLifecycleListener(GlobalResourcesLifecycleListener.class)
    			.addLifecycleListener(ThreadLocalLeakPreventionListener.class)
    			.addGlobalResource(memoryDatabase)
            .addService(DEFAULT_SERVICE_NAME)
            // TODO .withDefaultRealm()
            .setBackgroundProcessorDelay(0)
            .setStartStopThreads(0)
            .addExecutor(DEFAULT_EXECUTOR_NAME, "tomcat-exec-", DEFAULT_EXECUTOR_MIN, DEFAULT_EXECUTOR_MAX, EMPTY_MAP)
            .addConnector(Tomcat.PROTOCOL_BIO, httpPort, connConfig)
            .addConnector(Tomcat.PROTOCOL_AJP, ajpPort, connConfig)
            .addHost(LOCALHOST, "webapps");
}
 
开发者ID:pidster-dot-org,项目名称:embed-apache-tomcat,代码行数:32,代码来源:CatalinaBuilderImpl.java


示例5: configureServer

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
private static void configureServer(Server server) {
  LifecycleListener jasperListener = new JasperListener();
  server.addLifecycleListener(jasperListener);
  jasperListener.lifecycleEvent(new LifecycleEvent(server, Lifecycle.BEFORE_INIT_EVENT, null));
  server.addLifecycleListener(new JreMemoryLeakPreventionListener());
  server.addLifecycleListener(new ThreadLocalLeakPreventionListener());
}
 
开发者ID:apsaltis,项目名称:oryx,代码行数:8,代码来源:Runner.java


示例6: configureServer

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
private static void configureServer(Server server) {
  //server.addLifecycleListener(new SecurityListener());
  //server.addLifecycleListener(new AprLifecycleListener());
  LifecycleListener jasperListener = new JasperListener();
  server.addLifecycleListener(jasperListener);
  jasperListener.lifecycleEvent(new LifecycleEvent(server, Lifecycle.BEFORE_INIT_EVENT, null));
  server.addLifecycleListener(new JreMemoryLeakPreventionListener());
  //server.addLifecycleListener(new GlobalResourcesLifecycleListener());
  server.addLifecycleListener(new ThreadLocalLeakPreventionListener());
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:11,代码来源:Runner.java


示例7: testThreadLocalLeak1

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Test
public void testThreadLocalLeak1() throws Exception {

    Tomcat tomcat = getTomcatInstance();
    // Need to make sure we see a leak for the right reasons
    tomcat.getServer().addLifecycleListener(
            new JreMemoryLeakPreventionListener());

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "leakServlet1",
            "org.apache.tomcat.unittest.TesterLeakingServlet1");
    ctx.addServletMapping("/leak1", "leakServlet1");

    tomcat.start();

    Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
    ((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);

    // Configure logging filter to check leak message appears
    LogValidationFilter f = new LogValidationFilter(
            "The web application [] created a ThreadLocal with key of");
    LogManager.getLogManager().getLogger(
            "org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f);

    // Need to force loading of all web application classes via the web
    // application class loader
    loadClass("TesterCounter",
            (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    loadClass("TesterLeakingServlet1",
            (WebappClassLoaderBase) ctx.getLoader().getClassLoader());

    // This will trigger the ThreadLocal creation
    int rc = getUrl("http://localhost:" + getPort() + "/leak1",
            new ByteChunk(), null);

    // Make sure request is OK
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    // Destroy the context
    ctx.stop();
    tomcat.getHost().removeChild(ctx);
    ctx = null;

    // Make sure we have a memory leak
    String[] leaks = ((StandardHost) tomcat.getHost())
            .findReloadedContextMemoryLeaks();
    Assert.assertNotNull(leaks);
    Assert.assertTrue(leaks.length > 0);

    // Make sure the message was logged
    Assert.assertEquals(1, f.getMessageCount());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:55,代码来源:TestWebappClassLoaderThreadLocalMemoryLeak.java


示例8: testThreadLocalLeak2

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Test
public void testThreadLocalLeak2() throws Exception {

    Tomcat tomcat = getTomcatInstance();
    // Need to make sure we see a leak for the right reasons
    tomcat.getServer().addLifecycleListener(
            new JreMemoryLeakPreventionListener());

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "leakServlet2",
            "org.apache.tomcat.unittest.TesterLeakingServlet2");
    ctx.addServletMapping("/leak2", "leakServlet2");

    tomcat.start();

    Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
    ((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);

    // Configure logging filter to check leak message appears
    LogValidationFilter f = new LogValidationFilter(
            "The web application [] created a ThreadLocal with key of");
    LogManager.getLogManager().getLogger(
            "org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f);

    // Need to force loading of all web application classes via the web
    // application class loader
    loadClass("TesterCounter",
            (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    loadClass("TesterThreadScopedHolder",
            (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    loadClass("TesterLeakingServlet2",
            (WebappClassLoaderBase) ctx.getLoader().getClassLoader());

    // This will trigger the ThreadLocal creation
    int rc = getUrl("http://localhost:" + getPort() + "/leak2",
            new ByteChunk(), null);

    // Make sure request is OK
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    // Destroy the context
    ctx.stop();
    tomcat.getHost().removeChild(ctx);
    ctx = null;

    // Make sure we have a memory leak
    String[] leaks = ((StandardHost) tomcat.getHost())
            .findReloadedContextMemoryLeaks();
    Assert.assertNotNull(leaks);
    Assert.assertTrue(leaks.length > 0);

    // Make sure the message was logged
    Assert.assertEquals(1, f.getMessageCount());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:57,代码来源:TestWebappClassLoaderThreadLocalMemoryLeak.java


示例9: configureServer

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
private static void configureServer(Server server) {
  server.addLifecycleListener(new JreMemoryLeakPreventionListener());
  server.addLifecycleListener(new ThreadLocalLeakPreventionListener());
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:5,代码来源:ServingLayer.java


示例10: testThreadLocalLeak1

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Test
public void testThreadLocalLeak1() throws Exception {

    Tomcat tomcat = getTomcatInstance();
    // Need to make sure we see a leak for the right reasons
    tomcat.getServer().addLifecycleListener(
            new JreMemoryLeakPreventionListener());

    // Must have a real docBase - just use temp
    Context ctx = tomcat.addContext("",
            System.getProperty("java.io.tmpdir"));

    Tomcat.addServlet(ctx, "leakServlet1",
            "org.apache.tomcat.unittest.TesterLeakingServlet1");
    ctx.addServletMapping("/leak1", "leakServlet1");


    tomcat.start();

    // Configure logging filter to check leak message appears
    LogValidationFilter f = new LogValidationFilter(
            "The web application [] created a ThreadLocal with key of");
    LogManager.getLogManager().getLogger(
            "org.apache.catalina.loader.WebappClassLoader").setFilter(f);

    // Need to force loading of all web application classes via the web
    // application class loader
    loadClass("TesterCounter",
            (WebappClassLoader) ctx.getLoader().getClassLoader());
    loadClass("TesterLeakingServlet1",
            (WebappClassLoader) ctx.getLoader().getClassLoader());

    // This will trigger the ThreadLocal creation
    int rc = getUrl("http://localhost:" + getPort() + "/leak1",
            new ByteChunk(), null);

    // Make sure request is OK
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    // Destroy the context
    ctx.stop();
    tomcat.getHost().removeChild(ctx);
    ctx = null;

    // Make sure we have a memory leak
    String[] leaks = ((StandardHost) tomcat.getHost())
            .findReloadedContextMemoryLeaks();
    Assert.assertNotNull(leaks);
    Assert.assertTrue(leaks.length > 0);

    // Make sure the message was logged
    Assert.assertEquals(1, f.getMessageCount());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:54,代码来源:TestWebappClassLoaderThreadLocalMemoryLeak.java


示例11: testThreadLocalLeak2

import org.apache.catalina.core.JreMemoryLeakPreventionListener; //导入依赖的package包/类
@Test
public void testThreadLocalLeak2() throws Exception {

    Tomcat tomcat = getTomcatInstance();
    // Need to make sure we see a leak for the right reasons
    tomcat.getServer().addLifecycleListener(
            new JreMemoryLeakPreventionListener());

    // Must have a real docBase - just use temp
    Context ctx = tomcat.addContext("",
            System.getProperty("java.io.tmpdir"));

    Tomcat.addServlet(ctx, "leakServlet2",
            "org.apache.tomcat.unittest.TesterLeakingServlet2");
    ctx.addServletMapping("/leak2", "leakServlet2");

    tomcat.start();

    // Configure logging filter to check leak message appears
    LogValidationFilter f = new LogValidationFilter(
            "The web application [] created a ThreadLocal with key of");
    LogManager.getLogManager().getLogger(
            "org.apache.catalina.loader.WebappClassLoader").setFilter(f);

    // Need to force loading of all web application classes via the web
    // application class loader
    loadClass("TesterCounter",
            (WebappClassLoader) ctx.getLoader().getClassLoader());
    loadClass("TesterThreadScopedHolder",
            (WebappClassLoader) ctx.getLoader().getClassLoader());
    loadClass("TesterLeakingServlet2",
            (WebappClassLoader) ctx.getLoader().getClassLoader());

    // This will trigger the ThreadLocal creation
    int rc = getUrl("http://localhost:" + getPort() + "/leak2",
            new ByteChunk(), null);

    // Make sure request is OK
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    // Destroy the context
    ctx.stop();
    tomcat.getHost().removeChild(ctx);
    ctx = null;

    // Make sure we have a memory leak
    String[] leaks = ((StandardHost) tomcat.getHost())
            .findReloadedContextMemoryLeaks();
    Assert.assertNotNull(leaks);
    Assert.assertTrue(leaks.length > 0);

    // Make sure the message was logged
    Assert.assertEquals(1, f.getMessageCount());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:55,代码来源:TestWebappClassLoaderThreadLocalMemoryLeak.java



注:本文中的org.apache.catalina.core.JreMemoryLeakPreventionListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ComputationGraph类代码示例发布时间:2022-05-22
下一篇:
Java RecordConsumer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap