⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timerserviceimpl.java

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JAVA
字号:
/* * @author <a href="mailto:kisg@mailbox.hu">Gergely Kis</a> * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a> * @version $Id: TimerServiceImpl.java 4496 2006-02-08 20:27:04Z wehrens $ */package org.gridsphere.services.core.timer.impl;import org.gridsphere.portlet.service.PortletServiceUnavailableException;import org.gridsphere.portlet.service.spi.PortletServiceConfig;import org.gridsphere.portlet.service.spi.PortletServiceProvider;import org.gridsphere.services.core.timer.TimerService;import java.util.*;/** * Timer Service implementation based on the java.util.Timer API. */public class TimerServiceImpl implements PortletServiceProvider, TimerService {    private Map timerMap = new HashMap();    public void init(PortletServiceConfig config) throws PortletServiceUnavailableException {    }    public synchronized void destroy() {        Iterator timerIter = timerMap.values().iterator();        while (timerIter.hasNext()) {            Timer timer = (Timer) timerIter.next();            timer.cancel();        }    }    public synchronized void schedule(String timerId, TimerTask task, long delay) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer == null) {            timer = new Timer();            timerMap.put(timerId, timer);        }        timer.schedule(task, delay);    }    public synchronized void schedule(String timerId, TimerTask task, long delay, long period) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer == null) {            timer = new Timer();            timerMap.put(timerId, timer);        }        timer.schedule(task, delay, period);    }    public synchronized void cancel(String timerId) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer != null) {            timer.cancel();            timerMap.remove(timerId);        }    }    public synchronized void schedule(String timerId, TimerTask task, Date time) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer == null) {            timer = new Timer();            timerMap.put(timerId, timer);        }        timer.schedule(task, time);    }    public synchronized void schedule(String timerId, TimerTask task, Date firstTime, long period) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer == null) {            timer = new Timer();            timerMap.put(timerId, timer);        }        timer.schedule(task, firstTime, period);    }    public synchronized void scheduleAtFixedRate(String timerId, TimerTask task, long delay, long period) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer == null) {            timer = new Timer();            timerMap.put(timerId, timer);        }        timer.scheduleAtFixedRate(task, delay, period);    }    public synchronized void scheduleAtFixedRate(String timerId, TimerTask task, Date firstTime, long period) {        Timer timer = (Timer) timerMap.get(timerId);        if (timer == null) {            timer = new Timer();            timerMap.put(timerId, timer);        }        timer.scheduleAtFixedRate(task, firstTime, period);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -