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


Java Timer.cancel方法代碼示例

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


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

示例1: setFilterEnabled

import java.util.Timer; //導入方法依賴的package包/類
@Override
public synchronized void setFilterEnabled(boolean yes) {
	super.setFilterEnabled(yes);
	if (yes) {
		if (chip.getHardwareInterface() != null) {
			if (chip.getHardwareInterface() instanceof HasLEDControl) {
				ledControl = (HasLEDControl) chip.getHardwareInterface();
			}
		}
		ledTimer = new Timer("LED Flasher");
		ledTimer.schedule(new LEDSetterTask(), 0, periodMs / 2);
	} else {
		if (ledTimer != null) {
			ledTimer.cancel();
		}
		if (ledControl != null) {
			ledControl.setLEDState(0, HasLEDControl.LEDState.OFF);
		}
	}
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:21,代碼來源:ProximityLEDDetector.java

示例2: asyncRepeat

import java.util.Timer; //導入方法依賴的package包/類
public static synchronized TimerTask asyncRepeat(final Runnable r, final int repeatmillis, final int times, final Runnable last) {
    final int[] counter = new int[1];
    counter[0]=0;
    final Timer t = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            try {
                if (counter[0]++ >= times) {
                    t.cancel();

                    if (last!=null) last.run();

                    return;
                }
                r.run();
            } catch (Exception | Error e) {
                t.cancel();
            }
        }
    };
    t.schedule(task, repeatmillis, repeatmillis);

    return task;
}
 
開發者ID:quaap,項目名稱:SeafoodBerserker,代碼行數:26,代碼來源:Utils.java

示例3: test

import java.util.Timer; //導入方法依賴的package包/類
public static void test(Timer timer, String expected) throws InterruptedException {
    try {
        LinkedTransferQueue<String> queue = new LinkedTransferQueue<>();

        TimerTask task = new TimerTask() {
            public void run() {
                queue.put(Thread.currentThread().getName());
            }
        };

        timer.schedule(task, 0L); // immediately
        String actual = queue.take();

        if (!expected.equals(actual)) {
            throw new AssertionError(
                String.format("expected='%s', actual='%s'", expected, actual));
        }
    } finally {
        timer.cancel();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:NameConstructors.java

示例4: clearSearchView

import java.util.Timer; //導入方法依賴的package包/類
private void clearSearchView() {
    Timer timer = new Timer();
    try {
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (searchView != null && adapterElements != null && adapter != null)
                    if ((searchText == null || searchText.equals(""))) {
                        if (getActivity() != null)
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    searchedPlaces.clear();//clear all previously searched places
                                    adapterElements.clear();
                                    //reset the recyclerView
                                    adapter.resetAdapter();
                                }
                            });
                    }
            }
        }, 0, 1000);//Clear view every second
    } catch (Exception e) {
        timer.cancel();
    }
}
 
開發者ID:CityZenApp,項目名稱:Android-Development,代碼行數:26,代碼來源:SearchFragment.java

示例5: onMessage

import java.util.Timer; //導入方法依賴的package包/類
/**
 * Client onMessage get called to kill the job 
 * @param message
 * @param session
 */
@OnMessage
public void onMessage(String message, Session session) {
	logger.info("Trying to kill the job");
	final Timer timer = new Timer();
	TimerTask task = new TimerTask() {
		@Override
		public void run() {
			if (execution != null) {
				logger.info("Job killed successfully");
				execution.kill();
				timer.cancel();
			}
		}
			
	};
	timer.schedule(task, 0l, 600);
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:23,代碼來源:HydrographEngineCommunicatorSocket.java

示例6: actionPerformed

import java.util.Timer; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent evt) {
    plotterCache.remove(key);
    Timer t = timerCache.remove(key);
    t.cancel();
    ((XMBeanAttributes) table).collapse(attributeName, this);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:XPlottingViewer.java

示例7: timecount

import java.util.Timer; //導入方法依賴的package包/類
public void timecount() {
    timer = new Timer();
    timerTask = new TimerTask() {
        @Override
        public void run() {
            if (stopTimer) {
                timer.cancel();
            } else {
                delegate.getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        secondcount--;
                        delegate.getSmsView().setClickable(false);
                        delegate.getSmsView().setText("已發送(" + secondcount + "S)");
                        if (secondcount == 0) {
                            secondcount = 60;
                            delegate.getSmsView().setClickable(true);
                            delegate.getSmsView().setText("獲取驗證碼");
                            delegate.getSmsView().setClickable(true);
                            timer.cancel();
                        }
                    }
                });
            }

        }
    };
    timer.schedule(timerTask, 1000, 1000);
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:30,代碼來源:AddPhonePresenter.java

示例8: shutdown

import java.util.Timer; //導入方法依賴的package包/類
/**
 * Stops all cron jobs and clears cron job list.
 */
public static void shutdown() {
	CRONS.clear();

	for (final Timer timer : TIMERS) {
		timer.cancel();
	}

	TIMERS.clear();
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:13,代碼來源:CronService.java

示例9: main

import java.util.Timer; //導入方法依賴的package包/類
public static void main(String []s)
{
    final Dialog fd = new Dialog(new Frame(), true);
    Timer t = new Timer();
    t.schedule(new TimerTask() {

        public void run() {
            System.out.println("RUNNING TASK");
            fd.setVisible(false);
            fd.dispose();
            System.out.println("FINISHING TASK");
        }
    }, 3000L);

    fd.setVisible(true);
    t.cancel();
    Util.waitForIdle(null);

    AbstractTest.pass();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CrashXCheckJni.java

示例10: close

import java.util.Timer; //導入方法依賴的package包/類
public void close() {
	System.out.println("TaskCenter closing");
	this.monitoring.cancel(true);

	// 停止所有定時任務
	for (ScheduledFuture<?> sf : this.scheduledFutureList) {
		if (!sf.isCancelled() || !sf.isDone()) {
			sf.cancel(true);
		}
	}
	this.scheduledFutureList.clear();

	Iterator<Timer> iter = this.timers.values().iterator();
	while (iter.hasNext()) {
		Timer timer = iter.next();
		timer.cancel();
	}
	this.timers.clear();

	// 關閉滑動窗
	this.slidingWindow.stop();

	// 關閉線程池
	this.mainExecutor.shutdown();
	this.scheduledExecutor.shutdown();
	System.out.println("TaskCenter closed");
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:28,代碼來源:TaskCenter.java

示例11: StopTask

import java.util.Timer; //導入方法依賴的package包/類
/**
 * 停止當前任務(隻會由button UI觸發, 肯定為當前選中task)
 */
public void StopTask() {
    this.taskListModel.MarkTaskStatus(currentSelectTask.id, TaskStatus.STOPPED);
    NotifyAllObservers();

    // 停止定時抓取任務
    Timer timer = ApsvTimerManager.GetTimer(currentSelectTask.id);
    if (timer != null) {
        timer.cancel();
        timer.purge();
    }
    ApsvTimerManager.ClearStartTime(currentSelectTask.id);
}
 
開發者ID:thundernet8,項目名稱:AlipayOrdersSupervisor-GUI,代碼行數:16,代碼來源:RunTasksModel.java

示例12: transaction

import java.util.Timer; //導入方法依賴的package包/類
@Override
public void transaction() throws Exception {
    if (waitTask == null) {
        redisConnection.close();
        dataSourceService.deleteCompensates(getCompensateList());
        System.out.println("waitTask is null");
        return;
    }


    //start 結束就是全部事務的結束表示,考慮start掛掉的情況
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            System.out.println("自動回滾->" + getGroupId());
            dataSourceService.schedule(getGroupId(), getCompensateList(), waitTask);
        }
    }, getMaxOutTime());

    System.out.println("transaction-awaitTask->" + getGroupId());
    waitTask.awaitTask();

    timer.cancel();

    int rs = waitTask.getState();

    System.out.println("(" + getGroupId() + ")->單元事務(1:提交 0:回滾 -1:事務模塊網絡異常回滾 -2:事務模塊超時異常回滾):" + rs);

    if (rs == 1) {
        redisConnection.exec();
    }
    if (rs != -100) {
        dataSourceService.deleteCompensates(getCompensateList());
    }
    waitTask.remove();

}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:39,代碼來源:LCNRedisConnection.java

示例13: endConnection

import java.util.Timer; //導入方法依賴的package包/類
public void endConnection() {
	for(Timer t: gameTimers)
		t.cancel();
	super.endConnection();
	
	client.remove();
	
	serverInstance.onThreadDisconnect(this);
}
 
開發者ID:chrisj42,項目名稱:minicraft-plus-revived,代碼行數:10,代碼來源:MinicraftServerThread.java

示例14: Game

import java.util.Timer; //導入方法依賴的package包/類
public Game(Context context, int width, int height, int speed, int highscore, InterstitialAd bigAd) {
    this(context);

    this.bigAd = bigAd;
    game = new SnakeGame();
    renderer = new Renderer(game, width, height, highscore);

    random = new Random();

    setFocusableInTouchMode(true);
    requestFocus();
    setOnKeyListener((view, keyCode, e) -> {
        if (keyCode == KeyEvent.KEYCODE_BACK && e.getRepeatCount() == 0) {
            gotoMenu(context);
            return true;
        }
        return super.onKeyDown(keyCode, e);
    });

    setOnTouchListener((s, e) -> {
        if (game.isGameOver()) {
            gotoMenu(context);
            return true;
        }

        if (e.getAction() == MotionEvent.ACTION_UP) {
            game.changeDirection(
                    renderer.getGameX((int) e.getX()),
                    renderer.getGameY((int) e.getY())
            );
        }

        s.performClick();
        return true;
    });

    timer = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            game.update();
            postInvalidate();
            if (game.isGameOver()) {
                timer.cancel();
            }
        }
    };

    timer.schedule(task, 0, 700 / speed);
}
 
開發者ID:pontusstjerna,項目名稱:SnakeWear,代碼行數:51,代碼來源:Game.java

示例15: request

import java.util.Timer; //導入方法依賴的package包/類
/**
 * 發出請求,監聽dataMap響應,若指定時間內沒有收到返回則超時。
 *
 * @param context  c
 * @param path     必須以/開頭
 * @param data     byte[]
 * @param timeout  超時
 * @param callback 主線程回調,可null
 */
public static void request(
        final Context context, @NonNull final String path, @NonNull final byte[] data,
        final long timeout, @NonNull final BothwayCallback4DataMap callback) {
    final Timer timer = new Timer();
    @SuppressLint("HandlerLeak") final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            timer.cancel();
            switch (msg.what) {
                case HANDLER_SEND_FAILED:
                    WTLog.e(TAG, "Send bothway msg failed.");
                    callback.onFailed(RESULT_FAILED_SEND);
                    break;
                case HANDLER_RECEIVE_RESPONSE:
                    final ResponseDataBean dataBean = (ResponseDataBean) msg.obj;
                    WTLog.v(TAG, "Receive data map response. path:" + dataBean.path);
                    callback.onRespond(dataBean.dataMap);
                    break;
                case HANDLER_RESPONSE_TIME_OUT:
                    WTLog.e(TAG, "Bothway send or wait timeout.");
                    callback.onFailed(RESULT_FAILED_WAIT_TIME_OUT);
                    break;
            }
        }
    };

    //發送請求
    final long nanoTime = System.nanoTime();
    WTLog.v(TAG, "Send bothway msg. path:" + path);
    WTSender.sendMessage(context, path, mergeByte(BOTHWAY_REQUEST_FLAG, long2Bytes(nanoTime), data), timeout, new WTSender.SendMsgCallback() {
        @Override
        public void onSuccess() {
            regResponseDataListener(context, nanoTime, handler, long2Bytes(nanoTime));
        }

        @Override
        public void onFailed(int resultCode) {
            handler.sendEmptyMessage(HANDLER_SEND_FAILED);
        }
    });

    //設置超時
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            timer.cancel();
            if (dataListenerMap.get(nanoTime) != null) {
                WTLog.v(TAG, "Remove response data listener.");
                WTRegister.removeDataListener(context, dataListenerMap.get(nanoTime));
                dataListenerMap.remove(nanoTime);
            }
            handler.sendEmptyMessage(HANDLER_RESPONSE_TIME_OUT);
        }
    }, timeout);
}
 
開發者ID:liangchenhe55,項目名稱:WearTools,代碼行數:66,代碼來源:WTBothway.java


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