亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? memorytestcase.java

?? 這是一個有關(guān)common beanutils 的源碼
?? JAVA
字號:
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.beanutils.converters;

import java.lang.ref.WeakReference;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.ConversionException;

import junit.framework.TestCase;

/**
 * This class provides a number of unit tests related to classloaders and
 * garbage collection, particularly in j2ee-like situations.
 */
public class MemoryTestCase extends TestCase {

    public void testWeakReference() throws Exception {
        ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
        ClassReloader componentLoader = new ClassReloader(origContextClassLoader);

        Thread.currentThread().setContextClassLoader(componentLoader);
        Thread.currentThread().setContextClassLoader(origContextClassLoader);

        WeakReference ref = new WeakReference(componentLoader);
        componentLoader = null;

        forceGarbageCollection(ref);
        assertNull(ref.get());
        } finally {
            // Restore context classloader that was present before this
            // test started. It is expected to be the same as the system
            // classloader, but we handle all cases here..
            Thread.currentThread().setContextClassLoader(origContextClassLoader);

            // and restore all the standard converters
            ConvertUtils.deregister();
        }
    }

    /**
     * Test whether registering a standard Converter instance while
     * a custom context classloader is set causes a memory leak.
     *
     * <p>This test emulates a j2ee container where BeanUtils has been
     * loaded from a "common" lib location that is shared across all
     * components running within the container. The "component" registers
     * a converter object, whose class was loaded from the "common" lib
     * location. The registered converter:
     * <ul>
     * <li>should not be visible to other components; and</li>
     * <li>should not prevent the component-specific classloader from being
     *  garbage-collected when the container sets its reference to null.
     * </ul>
     *
     */
    public void testComponentRegistersStandardConverter() throws Exception {

        ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            // sanity check; who's paranoid?? :-)
            assertEquals(origContextClassLoader, ConvertUtils.class.getClassLoader());

            // create a custom classloader for a "component"
            // just like a container would.
            ClassLoader componentLoader1 = new ClassLoader() {};
            ClassLoader componentLoader2 = new ClassLoader() {};

            Converter origFloatConverter = ConvertUtils.lookup(Float.TYPE);
            Converter floatConverter1 = new FloatConverter();

            // Emulate the container invoking a component #1, and the component
            // registering a custom converter instance whose class is
            // available via the "shared" classloader.
            Thread.currentThread().setContextClassLoader(componentLoader1);
            {
                // here we pretend we're running inside component #1

                // When we first do a ConvertUtils operation inside a custom
                // classloader, we get a completely fresh copy of the
                // ConvertUtilsBean, with all-new Converter objects in it..
                assertFalse(ConvertUtils.lookup(Float.TYPE) == origFloatConverter);

                // Now we register a custom converter (but of a standard class).
                // This should only affect code that runs with exactly the
                // same context classloader set.
                ConvertUtils.register(floatConverter1, Float.TYPE);
                assertTrue(ConvertUtils.lookup(Float.TYPE) == floatConverter1);
            }
            Thread.currentThread().setContextClassLoader(origContextClassLoader);

            // The converter visible outside any custom component should not
            // have been altered.
            assertTrue(ConvertUtils.lookup(Float.TYPE) == origFloatConverter);

            // Emulate the container invoking a component #2.
            Thread.currentThread().setContextClassLoader(componentLoader2);
            {
                // here we pretend we're running inside component #2

                // we should get a completely fresh ConvertUtilsBean, with
                // all-new Converter objects again.
                assertFalse(ConvertUtils.lookup(Float.TYPE) == origFloatConverter);
                assertFalse(ConvertUtils.lookup(Float.TYPE) == floatConverter1);
            }
            Thread.currentThread().setContextClassLoader(origContextClassLoader);

            // Emulate a container "undeploying" component #1. This should
            // make component loader available for garbage collection (we hope)
            WeakReference weakRefToComponent1 = new WeakReference(componentLoader1);
            componentLoader1 = null;

            // force garbage collection and  verify that the componentLoader
            // has been garbage-collected
            forceGarbageCollection(weakRefToComponent1);
            assertNull(
                "Component classloader did not release properly; memory leak present",
                weakRefToComponent1.get());
        } finally {
            // Restore context classloader that was present before this
            // test started, so that in case of a test failure we don't stuff
            // up later tests...
            Thread.currentThread().setContextClassLoader(origContextClassLoader);

            // and restore all the standard converters
            ConvertUtils.deregister();
        }
    }

    /**
     * Test whether registering a custom Converter subclass while
     * a custom context classloader is set causes a memory leak.
     *
     * <p>This test emulates a j2ee container where BeanUtils has been
     * loaded from a "common" lib location that is shared across all
     * components running within the container. The "component" registers
     * a converter object, whose class was loaded via the component-specific
     * classloader. The registered converter:
     * <ul>
     * <li>should not be visible to other components; and</li>
     * <li>should not prevent the component-specific classloader from being
     *  garbage-collected when the container sets its reference to null.
     * </ul>
     *
     */
    public void testComponentRegistersCustomConverter() throws Exception {

        ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            // sanity check; who's paranoid?? :-)
            assertEquals(origContextClassLoader, ConvertUtils.class.getClassLoader());

            // create a custom classloader for a "component"
            // just like a container would.
            ClassReloader componentLoader = new ClassReloader(origContextClassLoader);

            // Load a custom Converter via component loader. This emulates what
            // would happen if a user wrote their own FloatConverter subclass
            // and deployed it via the component-specific classpath.
            Thread.currentThread().setContextClassLoader(componentLoader);
            {
              // Here we pretend we're running inside the component, and that
              // a class FloatConverter has been loaded from the component's
              // private classpath.
              Class newFloatConverterClass = componentLoader.reload(FloatConverter.class);
              Object newFloatConverter = newFloatConverterClass.newInstance();
              assertTrue(newFloatConverter.getClass().getClassLoader() == componentLoader);

              // verify that this new object does implement the Converter type
              // despite being loaded via a classloader different from the one
              // that loaded the Converter class.
              assertTrue(
                "Converter loader via child does not implement parent type",
                Converter.class.isInstance(newFloatConverter));

              // this converter registration will only apply to the
              // componentLoader classloader...
              ConvertUtils.register((Converter)newFloatConverter, Float.TYPE);

              // After registering a custom converter, lookup should return
              // it back to us. We'll try this lookup again with a different
              // context-classloader set, and shouldn't see it
              Converter componentConverter = ConvertUtils.lookup(Float.TYPE);
              assertTrue(componentConverter.getClass().getClassLoader() == componentLoader);

              newFloatConverter = null;
            }
            Thread.currentThread().setContextClassLoader(origContextClassLoader);

            // Because the context classloader has been reset, we shouldn't
            // see the custom registered converter here...
            Converter sharedConverter = ConvertUtils.lookup(Float.TYPE);
            assertFalse(sharedConverter.getClass().getClassLoader() == componentLoader);

            // and here we should see it again
            Thread.currentThread().setContextClassLoader(componentLoader);
            {
                Converter componentConverter = ConvertUtils.lookup(Float.TYPE);
                assertTrue(componentConverter.getClass().getClassLoader() == componentLoader);
            }
            Thread.currentThread().setContextClassLoader(origContextClassLoader);
            // Emulate a container "undeploying" the component. This should
            // make component loader available for garbage collection (we hope)
            WeakReference weakRefToComponent = new WeakReference(componentLoader);
            componentLoader = null;

            // force garbage collection and  verify that the componentLoader
            // has been garbage-collected
            forceGarbageCollection(weakRefToComponent);
            assertNull(
                "Component classloader did not release properly; memory leak present",
                weakRefToComponent.get());
        } finally {
            // Restore context classloader that was present before this
            // test started. It is expected to be the same as the system
            // classloader, but we handle all cases here..
            Thread.currentThread().setContextClassLoader(origContextClassLoader);

            // and restore all the standard converters
            ConvertUtils.deregister();
        }
    }

    /**
     * Attempt to force garbage collection of the specified target.
     *
     * <p>Unfortunately there is no way to force a JVM to perform
     * garbage collection; all we can do is <i>hint</i> to it that
     * garbage-collection would be a good idea, and to consume
     * memory in order to trigger it.</p>
     *
     * <p>On return, target.get() will return null if the target has
     * been garbage collected.</p>
     *
     * <p>If target.get() still returns non-null after this method has returned,
     * then either there is some reference still being held to the target, or
     * else we were not able to trigger garbage collection; there is no way
     * to tell these scenarios apart.</p>
     */
    private void forceGarbageCollection(WeakReference target) {
        int bytes = 2;

        while(target.get() != null) {
            System.gc();

            // Create increasingly-large amounts of non-referenced memory
            // in order to persuade the JVM to collect it. We are hoping
            // here that the JVM is dumb enough to run a full gc pass over
            // all data (including the target) rather than simply collecting
            // this easily-reclaimable memory!
            try {
                byte[] b =  new byte[bytes];
                bytes = bytes * 2;
            } catch(OutOfMemoryError e) {
                // well that sure should have forced a garbage collection
                // run to occur!
                break;
            }
        }

        // and let's do one more just to clean up any garbage we might have
        // created on the last pass..
        System.gc();
    }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区三区精品视频| 水野朝阳av一区二区三区| 久久国产三级精品| 日本韩国欧美一区二区三区| 国产丝袜美腿一区二区三区| 视频一区视频二区在线观看| 91啪亚洲精品| 国产欧美精品一区| 国产中文一区二区三区| 日韩一区二区在线观看| 亚洲高清视频在线| 色又黄又爽网站www久久| 国产日本欧洲亚洲| 久久97超碰国产精品超碰| 欧美理论在线播放| 亚洲一线二线三线久久久| 99国产精品久久| 国产精品污污网站在线观看| 国产剧情一区在线| 欧美大片一区二区| 青青草视频一区| 欧美一区三区四区| 午夜精品一区在线观看| 在线影视一区二区三区| 亚洲少妇中出一区| av在线播放不卡| 国产精品久久久久精k8| 国产成人高清视频| 国产色婷婷亚洲99精品小说| 精品一区二区影视| 久久综合999| 精品在线播放免费| 久久夜色精品国产噜噜av| 精品一区二区在线视频| 精品成人佐山爱一区二区| 久久草av在线| 久久色.com| 国产高清在线观看免费不卡| 日本一区二区免费在线观看视频 | 亚洲婷婷综合久久一本伊一区| 国产夫妻精品视频| 国产欧美日韩综合精品一区二区| 国产精品996| 国产日韩欧美一区二区三区综合| 国产精品1024久久| 欧美国产综合一区二区| av爱爱亚洲一区| 亚洲欧美乱综合| 在线免费亚洲电影| 亚洲chinese男男1069| 欧美男生操女生| 美女网站色91| 久久综合九色综合97_久久久| 极品瑜伽女神91| 日本一区二区免费在线| 91丨九色丨尤物| 亚洲综合无码一区二区| 欧美久久久久免费| 精品系列免费在线观看| 欧美国产国产综合| 色先锋aa成人| 亚洲一区在线视频观看| 日韩一二三区不卡| 高清beeg欧美| 亚洲一区二区三区四区五区黄 | 欧美性色综合网| 日本va欧美va瓶| 国产无人区一区二区三区| av一区二区三区在线| 亚洲成人动漫在线免费观看| 欧美一级二级三级乱码| 成人一区二区三区视频在线观看| 综合久久国产九一剧情麻豆| 欧美日韩亚州综合| 精东粉嫩av免费一区二区三区| 国产日产欧美一区二区视频| 91在线码无精品| 热久久国产精品| 国产精品第五页| 欧美老肥妇做.爰bbww| 国产麻豆精品theporn| 一区二区三区鲁丝不卡| 欧美变态tickling挠脚心| av中文字幕一区| 麻豆专区一区二区三区四区五区| 欧美极品另类videosde| 欧美日韩一区高清| 国产成人免费xxxxxxxx| 午夜激情一区二区三区| 国产午夜三级一区二区三| 欧美日韩在线播放| 成人综合在线观看| 亚洲第一福利视频在线| 久久久99精品久久| 欧美日韩一级黄| 国产91丝袜在线播放九色| 午夜激情一区二区三区| 国产精品国产三级国产a | 成人aaaa免费全部观看| 日本在线观看不卡视频| 国产精品久久午夜| 日韩精品专区在线影院重磅| 色婷婷综合久色| 国产一区二区三区高清播放| 亚洲永久精品大片| 国产欧美1区2区3区| 91精品国产91久久综合桃花 | 丁香一区二区三区| 日本欧美在线观看| 玉米视频成人免费看| 久久青草欧美一区二区三区| 欧美三级午夜理伦三级中视频| 国产成人免费网站| 久久成人久久爱| 亚洲电影中文字幕在线观看| 欧美经典三级视频一区二区三区| 日韩亚洲电影在线| 欧美性videosxxxxx| 92精品国产成人观看免费| 国产麻豆精品95视频| 美国三级日本三级久久99| 亚洲综合久久久久| 成人免费小视频| 久久精品欧美日韩| 日韩美女一区二区三区四区| 欧美日韩精品欧美日韩精品一综合| 成人黄色软件下载| 国产成人亚洲综合a∨猫咪| 日本亚洲一区二区| 亚洲国产精品久久久久秋霞影院 | 亚洲综合免费观看高清在线观看| 欧美国产成人在线| 久久亚洲私人国产精品va媚药| 欧美福利视频一区| 欧美性感一区二区三区| 91成人免费网站| 色婷婷av久久久久久久| 99r国产精品| 99视频一区二区三区| 国产激情视频一区二区三区欧美| 国模少妇一区二区三区| 青青草国产成人99久久| 午夜精品一区在线观看| 亚洲.国产.中文慕字在线| 亚洲精品视频一区| 尤物av一区二区| 亚洲欧美福利一区二区| 亚洲三级免费观看| 成人免费一区二区三区在线观看| 亚洲国产成人一区二区三区| 久久久精品免费观看| 久久精品亚洲精品国产欧美| 久久综合国产精品| 国产欧美一区二区三区在线老狼 | 欧美日韩国产乱码电影| 欧美日韩精品高清| 欧美精品v日韩精品v韩国精品v| 欧美日韩精品免费| 欧美一区二区三区在线观看 | 99精品偷自拍| 91视频精品在这里| 一本久道中文字幕精品亚洲嫩| 色视频一区二区| 欧美日韩一本到| 日韩一级片在线观看| 欧美va亚洲va香蕉在线| 久久精品亚洲国产奇米99| 国产欧美日韩精品一区| 日韩美女视频一区| 夜夜嗨av一区二区三区| 视频一区免费在线观看| 激情成人综合网| 成人免费毛片片v| 色婷婷久久久综合中文字幕| 欧美三级在线播放| 欧美xxxxx牲另类人与| 欧美激情一区二区三区在线| 亚洲欧美中日韩| 亚洲最新视频在线观看| 天天色天天操综合| 极品美女销魂一区二区三区| 国产91精品一区二区麻豆亚洲| 99久久伊人精品| 欧美日韩精品一区二区三区| 精品日韩一区二区三区| 国产精品乱码久久久久久| 一区二区三区精品| 蜜臀va亚洲va欧美va天堂| 国产福利视频一区二区三区| 99视频在线观看一区三区| 欧美日本精品一区二区三区| 欧美岛国在线观看| 国产精品初高中害羞小美女文| 亚洲国产精品一区二区久久| 国产综合色产在线精品| 9久草视频在线视频精品| 欧美精品免费视频| 国产精品污污网站在线观看| 婷婷国产在线综合| 成人免费毛片高清视频|