开发和调度任务
要开发和调度任务,请使用配置的调度程序。
过程
示例
您可以从任何 Java 应用程序中使用 SIMPLE 和 CRON 日程表。此示例将说明该过程。
使用缺省调度程序日程表。以下代码示例说明了如何正确和错误地使用连接。
使用缺省调度程序日程表涉及查询缺省 UserCalendarHome Enterprise JavaBeans (EJB) Home 对象、创建 UserCalendar Bean 和调用 applyDelta() 方法。有关 applyDelta 方法的详细信息以及 SIMPLE 和 CRON 日程表的语法,请参阅“UserCalendar 接口”主题。
import java.util.Date;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.ibm.websphere.scheduler.UserCalendar;
import com.ibm.websphere.scheduler.UserCalendarHome;
// Create an initial context
InitialContext ctx = new InitialContext();
// Lookup and narrow the default UserCalendar home.
UserCalendarHome defaultCalHome=(UserCalendarHome)
PortableRemoteObject.narrow(ctx.lookup(
UserCalendarHome.DEFAULT_CALENDAR_JNDI_NAME),
UserCalendarHome.class);
// Create the default UserCalendar instance.
UserCalendar defaultCal = defaultCalHome.create();
// Calculate a date using CRON based on the current
// date and time. Return the next date that is
// Saturday at 2AM
Date newDate =
defaultCal.applyDelta(new Date(),
"CRON", "0 0 2 ? * SAT");