Search in sources :

Example 81 with Timer

use of java.util.Timer in project platform_frameworks_base by android.

the class LocationBasedCountryDetectorTest method waitForTimerReset.

private void waitForTimerReset(TestCountryDetector detector) {
    int count = 5;
    long interval = 1000;
    try {
        while (count-- > 0 && detector.getTimer() != null) {
            Thread.sleep(interval);
        }
    } catch (InterruptedException e) {
    }
    Timer timer = detector.getTimer();
    assertTrue(timer == null);
}
Also used : Timer(java.util.Timer)

Example 82 with Timer

use of java.util.Timer in project antlr4 by antlr.

the class SharedWebDriver method close.

public static void close() {
    if (driver != null) {
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                driver.quit();
                driver = null;
            }
        }, // close with delay to allow next Test to start
        2000);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 83 with Timer

use of java.util.Timer in project camel by apache.

the class QuickfixjProducerTest method processInOutExchangeSendUnsuccessful.

@Test
public void processInOutExchangeSendUnsuccessful() throws Exception {
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
    Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_CRITERIA_KEY)).thenReturn(new MessagePredicate(sessionID, MsgType.EMAIL));
    Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_TIMEOUT_KEY, 1000L, Long.class)).thenReturn(5000L);
    org.apache.camel.Message mockOutboundCamelMessage = Mockito.mock(org.apache.camel.Message.class);
    Mockito.when(mockExchange.getOut()).thenReturn(mockOutboundCamelMessage);
    final Message outboundFixMessage = new Email();
    outboundFixMessage.getHeader().setString(SenderCompID.FIELD, "TARGET");
    outboundFixMessage.getHeader().setString(TargetCompID.FIELD, "SENDER");
    Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
    Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
    Mockito.doAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        quickfixjEngine.getMessageCorrelator().onEvent(QuickfixjEventCategory.AppMessageReceived, sessionID, outboundFixMessage);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }, 10);
            return false;
        }
    }).when(mockSession).send(Matchers.isA(Message.class));
    producer.process(mockExchange);
    Mockito.verify(mockOutboundCamelMessage, Mockito.never()).setBody(Matchers.isA(Message.class));
    Mockito.verify(mockSession).send(inboundFixMessage);
    Mockito.verify(mockExchange).setException(Matchers.isA(CannotSendException.class));
}
Also used : Email(quickfix.fix42.Email) Message(quickfix.Message) IOException(java.io.IOException) JMException(javax.management.JMException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Session(quickfix.Session) Test(org.junit.Test)

Example 84 with Timer

use of java.util.Timer in project cube-sdk by liaohuqiu.

the class SystemWatcher method run.

public void run() {
    mTimerTask = new TimerTask() {

        @Override
        public void run() {
            MemoryInfo mi = new MemoryInfo();
            ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE);
            activityManager.getMemoryInfo(mi);
            Runtime runtime = Runtime.getRuntime();
            String s = String.format("free:%s%% %sKB total:%sKB max:%sKB ", runtime.freeMemory() * 100f / runtime.totalMemory(), runtime.freeMemory(), runtime.totalMemory() / 1024, runtime.maxMemory() / 1024);
            // s += String.format("native: free:%sKB total:%sKB max:%sKB", android.os.Debug.getNativeHeapFreeSize() / 1024, android.os.Debug.getNativeHeapAllocatedSize() / 1024,
            // android.os.Debug.getNativeHeapSize() / 1024);
            // s += String.format("| availMem:%sKB", mi.availMem / 1024);
            Log.d("memory", s);
        }
    };
    mTimer = new Timer();
    mTimer.schedule(mTimerTask, 1000, 1000);
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) TimerTask(java.util.TimerTask) Timer(java.util.Timer) ActivityManager(android.app.ActivityManager)

Example 85 with Timer

use of java.util.Timer in project JieCaoVideoPlayer by lipangit.

the class JCVideoPlayer method startProgressTimer.

public void startProgressTimer() {
    cancelProgressTimer();
    UPDATE_PROGRESS_TIMER = new Timer();
    mProgressTimerTask = new ProgressTimerTask();
    UPDATE_PROGRESS_TIMER.schedule(mProgressTimerTask, 0, 300);
}
Also used : Timer(java.util.Timer)

Aggregations

Timer (java.util.Timer)448 TimerTask (java.util.TimerTask)262 IOException (java.io.IOException)33 Date (java.util.Date)22 Test (org.junit.Test)15 File (java.io.File)11 ArrayList (java.util.ArrayList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9 Intent (android.content.Intent)8 Location (android.location.Location)8 LocationListener (android.location.LocationListener)8 Bundle (android.os.Bundle)8 ActivitiException (org.activiti.engine.ActivitiException)8 View (android.view.View)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 ImageView (android.widget.ImageView)7 BufferedReader (java.io.BufferedReader)7 InputStreamReader (java.io.InputStreamReader)7