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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? testconcurrency.java

?? oscache-2.4.1-full
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
        String key = "blocking";
        String NEW_VALUE = VALUE + " abc";
        admin.putInCache(key, VALUE);

        try {
            // Force a NeedsRefreshException
            admin.getFromCache(key, 0);
            fail("NeedsRefreshException should have been thrown");
        } catch (NeedsRefreshException nre) {
            // Fire off another thread to get the same cache entry.
            // Since blocking mode is enabled this thread should block
            // until the entry has been updated.
            GetEntry getEntry = new GetEntry(key, NEW_VALUE, 0, false);
            Thread thread = new Thread(getEntry);
            thread.start();

            // Sleep for a bit to simulate the time taken to build the cache entry
            try {
                Thread.sleep(200);
            } catch (InterruptedException ie) {
            }

            // Putting the entry in the cache should mean that threads now retrieve
            // the updated entry
            admin.putInCache(key, NEW_VALUE);

            getEntry = new GetEntry(key, NEW_VALUE, -1, false);
            thread = new Thread(getEntry);
            thread.start();

            try {
                Object fromCache = admin.getFromCache(key, -1);
                assertEquals(NEW_VALUE, fromCache);
            } catch (NeedsRefreshException e) {
                admin.cancelUpdate(key);
                fail("Should not have received a NeedsRefreshException");
            }
        }
    }

    /**
     * Checks whether the cache handles simultaneous attempts to access a
     * stable cache entry correctly when the blocking mode is enabled.
     *
     * Basically N threads are concurrently trying to access a same stale cache entry and each is cancelling its update. Each thread repeat this operation M times.
     * The test is sucessfull if after some time, all threads are properly released
     */
    public void testConcurrentStaleGets() {
        GeneralCacheAdministrator staticAdmin = admin;
        admin = new GeneralCacheAdministrator(); //avoid poluting other test cases

        try {
            // A test for the case where oscache.blocking = true
            //admin.destroy();
            Properties p = new Properties();
            p.setProperty(AbstractCacheAdministrator.CACHE_BLOCKING_KEY, "true");
            admin = new GeneralCacheAdministrator(p);

            assertTrue("The cache should be in blocking mode for this test.", admin.isBlocking());

            int nbThreads = 50;
            int retryByThreads = 10000;

            String key = "new";

            //First put a value
            admin.putInCache(key, VALUE);

            try {
                //Then test without concurrency that it is reported as stale when time-to-live is zero 
                admin.getFromCache(key, 0);
                fail("NeedsRefreshException should have been thrown");
            } catch (NeedsRefreshException nre) {
                //Ok this is was is excpected, we can release the update
                admin.cancelUpdate(key);
            }

            //Then ask N threads to concurrently try to access this stale resource and each should receive a NeedsRefreshException, and cancel the update
            Thread[] spawnedThreads = new Thread[nbThreads];
            BitSet successfullThreadTerminations = new BitSet(nbThreads); //Track which thread successfully terminated

            for (int threadIndex = 0; threadIndex < nbThreads; threadIndex++) {
                GetStaleEntryAndCancelUpdate getEntry = new GetStaleEntryAndCancelUpdate(key, 0, retryByThreads, threadIndex, successfullThreadTerminations);
                Thread thread = new Thread(getEntry);
                spawnedThreads[threadIndex] = thread;
                thread.start();
            }

            // OK, those threads should now repeatidely be blocked waiting for the new cache
            // entry to appear. Wait for all of them to terminate
            long maxWaitingSeconds = 100;
            int maxWaitForEachThread = 5;
            long waitStartTime = System.currentTimeMillis();

            boolean atLeastOneThreadRunning = false;

            while ((System.currentTimeMillis() - waitStartTime) < (maxWaitingSeconds * 1000)) {
                atLeastOneThreadRunning = false;

                //Wait a bit between each step to avoid consumming all CPU and preventing other threads from running.
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ie) {
                }

                //check whether all threads are done.
                for (int threadIndex = 0; threadIndex < nbThreads;
                        threadIndex++) {
                    Thread inspectedThread = spawnedThreads[threadIndex];

                    try {
                        inspectedThread.join(maxWaitForEachThread * 1000);
                    } catch (InterruptedException e) {
                        fail("Thread #" + threadIndex + " was interrupted");
                    }

                    if (inspectedThread.isAlive()) {
                        atLeastOneThreadRunning = true;
                        log.error("Thread #" + threadIndex + " did not complete within [" + ((System.currentTimeMillis() - waitStartTime) / 1000) + "] s ");
                    }
                }

                if (!atLeastOneThreadRunning) {
                    break; //while loop, test success.
                }
            }

            assertTrue("at least one thread did not complete within [" + ((System.currentTimeMillis() - waitStartTime) / 1000) + "] s ", !atLeastOneThreadRunning);

            for (int threadIndex = 0; threadIndex < nbThreads; threadIndex++) {
                assertTrue("thread [" + threadIndex + "] did not successfully complete. ", successfullThreadTerminations.get(threadIndex));
            }
        } finally {
            admin = staticAdmin;

            //Avoid po
        }
    }

    private class GetEntry implements Runnable {
        String key;
        String value;
        boolean expectNRE;
        int time;

        GetEntry(String key, String value, int time, boolean expectNRE) {
            this.key = key;
            this.value = value;
            this.time = time;
            this.expectNRE = expectNRE;
        }

        public void run() {
            try {
                // Get from the cache
                Object fromCache = admin.getFromCache(key, time);
                assertEquals(value, fromCache);
            } catch (NeedsRefreshException nre) {
                if (!expectNRE) {
                    admin.cancelUpdate(key);
                    fail("Thread should have blocked until a new cache entry was ready");
                } else {
                    // Put a new piece of content into the cache
                    admin.putInCache(key, value);
                }
            }
        }
    }

    /**
      * Basically requests a stale entry, expects to receive a NeedsRefreshException, and always cancels the update.
      */
    private class GetStaleEntryAndCancelUpdate implements Runnable {
        String key;
        int retries;
        int time;
        private final BitSet successfullThreadTerminations;
        private final int threadIndex;

        GetStaleEntryAndCancelUpdate(String key, int time, int retries, int threadIndex, BitSet successfullThreadTerminations) {
            this.key = key;
            this.time = time;
            this.retries = retries;
            this.threadIndex = threadIndex;
            this.successfullThreadTerminations = successfullThreadTerminations;
        }

        public void run() {
            for (int retryIndex = 0; retryIndex < retries; retryIndex++) {
                try {
                    // Get from the cache
                    Object fromCache = admin.getFromCache(key, time);
                    assertNull("Thread index [" + retryIndex + "] expected stale request [" + retryIndex + "] to be received, got [" + fromCache + "]", fromCache);
                } catch (NeedsRefreshException nre) {
                    try {
                        admin.cancelUpdate(key);
                    } catch (Throwable t) {
                        log.error("Thread index [" + retryIndex + "]: Unexpectedly caught exception [" + t + "]", t);
                        fail("Thread index [" + retryIndex + "] : Unexpectedly caught exception [" + t + "]");
                    }
                } catch (Throwable t) {
                    log.error("Thread index [" + retryIndex + "] : Unexpectedly caught exception [" + t + "]", t);
                    fail("Thread index [" + retryIndex + "] : Unexpectedly caught exception [" + t + "]");
                }
            }

            //Once we successfully terminate, we update the corresponding bit to let the Junit know we succeeded.
            synchronized (successfullThreadTerminations) {
                successfullThreadTerminations.set(threadIndex);
            }
        }
    }

    private class OSGeneralTest implements Runnable {
        public void doit(int i) {
            int refreshPeriod = 500 /*millis*/;
            String key = KEY + (i % UNIQUE_KEYS);
            admin.putInCache(key, VALUE);

            try {
                // Get from the cache
                admin.getFromCache(KEY, refreshPeriod);
            } catch (NeedsRefreshException nre) {
                // Get the value
                // Store in the cache
                admin.putInCache(KEY, VALUE);
            }

            // Flush occasionally
            if ((i % (UNIQUE_KEYS + 1)) == 0) {
                admin.getCache().flushEntry(key);
            }
        }

        public void run() {
            int start = (int) (Math.random() * UNIQUE_KEYS);
            System.out.print(start + " ");

            for (int i = start; i < (start + ITERATION_COUNT); i++) {
                doit(i);
            }
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人黄色在线视频| 久久亚洲精品国产精品紫薇| youjizz久久| 中文乱码免费一区二区| 99综合影院在线| 亚洲黄色在线视频| 欧美人xxxx| 麻豆久久一区二区| 国产无人区一区二区三区| 国产黄人亚洲片| 国产精品盗摄一区二区三区| 在线观看视频91| 久久精品国产澳门| 国产日产欧产精品推荐色| av电影在线观看不卡| 亚洲一线二线三线视频| 欧美一卡二卡在线观看| 国产真实乱偷精品视频免| **网站欧美大片在线观看| 欧美人狂配大交3d怪物一区| 国产伦理精品不卡| 一区二区三区资源| 日韩午夜在线播放| 91色九色蝌蚪| 经典三级在线一区| 洋洋成人永久网站入口| 日韩午夜三级在线| av激情亚洲男人天堂| 天堂一区二区在线| 国产精品丝袜久久久久久app| 在线观看一区二区精品视频| 国内一区二区在线| 一个色在线综合| 久久人人爽爽爽人久久久| 色偷偷成人一区二区三区91| 久久不见久久见免费视频7| 亚洲视频一区在线| 精品va天堂亚洲国产| 91福利在线看| 成人免费va视频| 久久成人免费网| 亚洲一卡二卡三卡四卡无卡久久| 精品欧美一区二区在线观看| 色婷婷一区二区三区四区| 国产精品911| 免费成人结看片| 亚洲超碰97人人做人人爱| 国产精品久久看| 久久久久久久久伊人| 777午夜精品视频在线播放| 91免费观看视频在线| 福利电影一区二区| 激情文学综合插| 视频一区中文字幕国产| 亚洲六月丁香色婷婷综合久久| 久久久久久久国产精品影院| 欧美一区二区高清| 欧美另类久久久品| 欧洲一区二区三区免费视频| 99re在线视频这里只有精品| 国产精品一二三四五| 久久爱www久久做| 久久aⅴ国产欧美74aaa| 日本欧美久久久久免费播放网| 亚洲综合免费观看高清完整版| 国产精品家庭影院| 中文字幕av免费专区久久| 欧美经典一区二区| 久久蜜桃一区二区| 久久综合久色欧美综合狠狠| 欧美大片日本大片免费观看| 91精品国产色综合久久不卡电影| 欧美日韩国产小视频在线观看| 欧美中文字幕久久 | 免费观看成人鲁鲁鲁鲁鲁视频| 亚洲国产日韩综合久久精品| 亚洲成人午夜电影| 偷窥少妇高潮呻吟av久久免费| 午夜视频在线观看一区二区| 视频一区中文字幕| 麻豆极品一区二区三区| 毛片基地黄久久久久久天堂| 久久精品国产99国产| 国内精品免费在线观看| 国产成人av在线影院| 成人a级免费电影| 色视频欧美一区二区三区| 色天天综合久久久久综合片| 欧美色手机在线观看| 欧美精品视频www在线观看| 欧美一区二区三区四区久久| 久久综合久久综合亚洲| 国产精品美女久久久久久久 | 一区二区不卡在线视频 午夜欧美不卡在 | 精品一区二区在线免费观看| 国产一区中文字幕| 成人国产精品免费网站| 欧美专区日韩专区| 欧美大片日本大片免费观看| 欧美国产激情二区三区| 一区二区三区四区国产精品| 午夜精品久久久久久久蜜桃app| 久久国产免费看| 99九九99九九九视频精品| 在线观看一区二区精品视频| 欧美哺乳videos| 综合电影一区二区三区| 五月婷婷欧美视频| 成人免费视频一区| 欧美高清视频不卡网| 久久综合国产精品| 亚洲成人自拍网| 狠狠网亚洲精品| 色88888久久久久久影院野外| 91精品国产综合久久久久| 中文字幕欧美激情| 天天操天天干天天综合网| 国产91在线看| 欧美高清视频一二三区| 欧美国产激情二区三区| 日韩成人免费电影| 不卡的av在线播放| 日韩美女一区二区三区四区| 中文字幕永久在线不卡| 蜜臂av日日欢夜夜爽一区| 91免费在线看| 久久久久久久久久久黄色| 亚洲成人资源网| jizz一区二区| 亚洲图片欧美视频| 成人激情视频网站| 日韩女优av电影| 亚洲女厕所小便bbb| 国产一区二区免费在线| 欧美伦理电影网| 一区二区三区日本| 成人黄色一级视频| 日本sm残虐另类| 日韩限制级电影在线观看| 国产河南妇女毛片精品久久久 | 一区二区三区蜜桃| 国产成人午夜精品5599| 欧美一级爆毛片| 午夜视频久久久久久| 色综合久久88色综合天天免费| 久久精品一区二区| 久久99深爱久久99精品| 欧美一区二区三区影视| 亚洲综合无码一区二区| 91网站在线观看视频| 欧美国产成人精品| 国产精品一区二区久久不卡 | 亚洲超碰97人人做人人爱| 91国偷自产一区二区开放时间 | 激情五月播播久久久精品| 欧美日韩国产精品自在自线| 亚洲精品中文在线观看| 菠萝蜜视频在线观看一区| 国产人妖乱国产精品人妖| 国产精品456| 国产日本欧洲亚洲| 成人免费观看av| 国产精品成人免费| 精品粉嫩超白一线天av| 国产在线播放一区二区三区| 精品国产免费人成在线观看| 久久国产精品第一页| 久久一区二区三区国产精品| 国产精品一区二区三区网站| 国产欧美一区二区精品久导航| 国产成人午夜视频| 成人欧美一区二区三区在线播放| 成人av综合一区| 一区二区三区不卡视频在线观看| 91视频观看视频| 午夜伊人狠狠久久| 欧美日本在线看| 久久爱www久久做| 国产三级欧美三级| av一本久道久久综合久久鬼色| 亚洲三级在线观看| 欧美精品777| 九九九精品视频| 中文字幕不卡的av| 在线观看免费成人| 美女视频黄 久久| 国产亚洲短视频| 色婷婷精品大在线视频| 午夜不卡在线视频| 精品精品国产高清一毛片一天堂| 国产电影一区二区三区| 亚洲激情图片一区| 日韩一区国产二区欧美三区| 国内成人免费视频| 亚洲精品久久嫩草网站秘色| 在线播放/欧美激情| 丁香婷婷综合网| 亚洲丶国产丶欧美一区二区三区| 欧美电影免费观看高清完整版在线观看| 国产盗摄视频一区二区三区|