當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestProcessor.stop方法代碼示例

本文整理匯總了Java中org.openide.util.RequestProcessor.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestProcessor.stop方法的具體用法?Java RequestProcessor.stop怎麽用?Java RequestProcessor.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openide.util.RequestProcessor的用法示例。


在下文中一共展示了RequestProcessor.stop方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testScheduleOneShot

import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
public void testScheduleOneShot() throws Exception {
    RequestProcessor rp = new RequestProcessor ("testScheduleOneShot", 5, true, true);
    try {
        class C implements Callable<String> {
            volatile long start = System.currentTimeMillis();
            private volatile long end;

            @Override
            public String call() throws Exception {
                synchronized(this) {
                    end = System.currentTimeMillis();
                }
                return "Hello";
            }

            synchronized long elapsed() {
                return end - start;
            }
        }
        C c = new C();
        long delay = 5000;
        //Use a 20 second timeout to have a reasonable chance of accuracy
        ScheduledFuture<String> f = rp.schedule(c, delay * 1000, TimeUnit.MICROSECONDS);
        assertEquals (5000, f.getDelay(TimeUnit.MILLISECONDS));
        assertNotNull(f.get());
        //Allow 4 seconds fudge-factor
        assertTrue (c.elapsed() > 4600);
        assertTrue (f.isDone());
    } finally {
        rp.stop();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:RequestProcessor180386Test.java

示例2: testScheduleFixedRateOnMultiThreadPoolDoesNotCauseConcurrentExecution

import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
public void testScheduleFixedRateOnMultiThreadPoolDoesNotCauseConcurrentExecution() throws Exception {
    final AtomicInteger val = new AtomicInteger(0);
    final CountDownLatch latch = new CountDownLatch(10);
    class C implements Runnable {
        boolean failed;
        @Override
        public void run() {
            try {
                int now = val.incrementAndGet();
                if (now > 1) {
                    failed = true;
                    fail (now + " threads simultaneously in run()");
                }
                try {
                    //Intentionally sleep *longer* than the interval
                    //between executions.  We *want* to pile up all of the
                    //RP threads entering run() - synchronization should
                    //serialize them.  This test is to prove that this
                    //method will never be called concurrently from two threads
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {

                }
            } finally {
                val.decrementAndGet();
                latch.countDown();
            }
        }
    }
    C c = new C();
    long initialDelay = 2000;
    long period = 10;
    RequestProcessor rp = new RequestProcessor("testScheduleFixedRateOnMultiThreadPoolDoesNotCauseConcurrentExecution", 10, true);
    rp.scheduleAtFixedRate(c, initialDelay, period, TimeUnit.MILLISECONDS);
    latch.await();
    assertFalse(c.failed);
    rp.stop();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:RequestProcessor180386Test.java

示例3: testScheduleFixedRateWithShorterIntervalThanRunMethodTimeAreNotDelayed

import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
@RandomlyFails
public void testScheduleFixedRateWithShorterIntervalThanRunMethodTimeAreNotDelayed() throws Exception {
    final CountDownLatch latch = new CountDownLatch(10);
    final List<Long> intervals = new CopyOnWriteArrayList<Long>();
    class C implements Runnable {
        long start = Long.MIN_VALUE;

        @Override
        public void run() {
            long end = System.currentTimeMillis();
            if (start != Long.MIN_VALUE) {
                intervals.add(end - start);
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                
            }
            start = System.currentTimeMillis();
            latch.countDown();
        }
    }
    C c = new C();
    long initialDelay = 100;
    long period = 100;
    RequestProcessor rp = new RequestProcessor("testScheduleFixedRateWithShorterIntervalThanRunMethodTimeAreNotDelayed", 10, true);
    ScheduledFuture<?> f = rp.scheduleAtFixedRate(c, initialDelay, period, TimeUnit.MILLISECONDS);
    latch.await();
    f.cancel(true);
    rp.stop();
    int max = intervals.size();
    for (int i= 0; i < max; i++) {
        long iv = intervals.get(i);
        assertFalse ("Interval " + i + " should have been at least less than requested interval * 1.5 with fixed rate" + iv, iv > 150);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:RequestProcessor180386Test.java

示例4: testScheduleRepeatingIntervalsAreRoughlyCorrect

import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
@RandomlyFails // NB-Core-Build #8322: hung
    public void testScheduleRepeatingIntervalsAreRoughlyCorrect() throws Exception {
        int runCount = 5;
        final CountDownLatch latch = new CountDownLatch(runCount);
        final List<Long> intervals = Collections.synchronizedList(new ArrayList<Long> (runCount));
//        long initialDelay = 30000;
//        long period = 20000;
//        long fudgeFactor = 4000;
        long initialDelay = 3000;
        long period = 2000;
        long fudgeFactor = 400;
        long expectedInitialDelay = initialDelay - fudgeFactor;
        long expectedPeriod = period - fudgeFactor;
        class C implements Runnable {
            volatile long start = System.currentTimeMillis();
            private int runCount;
            @Override
            public void run() {
                runCount++;
                try {
                    synchronized(this) {
                        long end = System.currentTimeMillis();
                        intervals.add (end - start);
                        start = end;
                    }
                } finally {
                    latch.countDown();
                }
            }
        }
        C c = new C();
        RequestProcessor rp = new RequestProcessor ("testScheduleRepeating", 5, true);
        try {
            Future<?> f = rp.scheduleWithFixedDelay(c, initialDelay, period, TimeUnit.MILLISECONDS);
    //        latch.await(initialDelay + fudgeFactor + ((runCount - 1) * (period + fudgeFactor)), TimeUnit.MILLISECONDS); //XXX
            latch.await();
            f.cancel(true);
            for (int i= 0; i < Math.min(runCount, intervals.size()); i++) {
                long expect = i == 0 ? expectedInitialDelay : expectedPeriod;
                assertTrue ("Expected at least " + expect + " milliseconds before run " + i + " but was " + intervals.get(i), intervals.get(i) >= expect);
            }
            //Ensure we have really exited
            try {
                f.get();
                fail ("CancellationException should have been thrown");
            } catch (CancellationException e) {}
            assertTrue(f.isCancelled());
            assertTrue(f.isDone());
        } finally {
            rp.stop();
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:53,代碼來源:RequestProcessor180386Test.java

示例5: testScheduleFixedRateAreRoughlyCorrect

import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
@RandomlyFails
    public void testScheduleFixedRateAreRoughlyCorrect() throws Exception {
        if (!TaskTest.canWait1s()) {
            LOG.warning("Skipping testWaitWithTimeOutReturnsAfterTimeOutWhenTheTaskIsNotComputedAtAll, as the computer is not able to wait 1s!");
            return;
        }
        int runCount = 5;
        final CountDownLatch latch = new CountDownLatch(runCount);
        final List<Long> intervals = Collections.synchronizedList(new ArrayList<Long> (runCount));
//        long initialDelay = 30000;
//        long period = 20000;
//        long fudgeFactor = 4000;
        long initialDelay = 3000;
        long period = 2000;
        long fudgeFactor = 400;
        long expectedInitialDelay = initialDelay - fudgeFactor;
        long expectedPeriod = period - fudgeFactor;
        class C implements Runnable {
            volatile long start = System.currentTimeMillis();
            private int runCount;
            @Override
            public void run() {
                runCount++;
                try {
                    synchronized(this) {
                        long end = System.currentTimeMillis();
                        intervals.add (end - start);
                        start = end;
                    }
                } finally {
                    latch.countDown();
                }
            }
        }
        C c = new C();
        RequestProcessor rp = new RequestProcessor ("testScheduleFixedRateAreRoughlyCorrect", 5, true);
        try {
            Future<?> f = rp.scheduleAtFixedRate(c, initialDelay, period, TimeUnit.MILLISECONDS);
            latch.await();
            f.cancel(true);
            StringBuilder failures = new StringBuilder();
            failures.append("Expected at least ").append(expectedInitialDelay).
                append(" milliseconds before run:\n");
            boolean fail = false;
            for (int i= 0; i < Math.min(runCount, intervals.size()); i++) {
                long expect = i == 0 ? expectedInitialDelay : expectedPeriod;
                failures.append("Round ").append(i).
                    append(" expected delay ").append(expect).
                    append(" but was ").append(intervals.get(i)).
                    append("\n");
                if (intervals.get(i) < expect) {
                    fail = true;
                }
            }
            if (fail) {
                fail(failures.toString());
            }
            //Ensure we have really exited
            try {
                f.get();
                fail ("CancellationException should have been thrown");
            } catch (CancellationException e) {}
            assertTrue(f.isCancelled());
            assertTrue(f.isDone());
        } finally {
            rp.stop();
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:69,代碼來源:RequestProcessor180386Test.java


注:本文中的org.openide.util.RequestProcessor.stop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。