ジョブ・スケジューラーの Enterprise JavaBeans (EJB) インターフェースを使用して、プログラムでバッチ・ジョブのサブミットおよび操作を行います。WebSphere® Application Server の基本スケジューラーで EJB インターフェースを使用して、バッチ・ジョブのカレンダー・ベースのサブミットを実行することができます。
始める前に
ジョブ・スケジューラーでは、Java™ Platform, Enterprise Edition (Java EE) アプリケーション向けの EJB インターフェースおよび Java EE と非 Java EE の両方のアプリケーション向けの Web サービス・インターフェースの両方を介する、そのジョブ・スケジューラー機能へのプログラムによるアクセスをサポートしています。ジョブ・スケジューラーの EJB インターフェースは、API の資料に記載されているインターフェースで記述されています。詳しくは、この資料を参照してください。
バッチ・アプリケーションを開発してインストールします。
このタスクについて
このトピックでは、基本スケジューラーを使用して、バッチ・ジョブをジョブ・スケジューラーにサブミットする方法を説明します。ここでは、
ジョブ・スケジューラー EJB を呼び出す方法を示すコード例も紹介します。
手順
- スケジューラーを作成して構成します。スケジューラーを作成して構成する方法については、タスクの開発とスケジューリングに関するトピックを参照してください。
- バッチ作業をサブミットするためのスケジューラー・タスクを作成します。
このスケジューラー・タスクは、ジョブ・スケジューラー EJB を呼び出して バッチ・ジョブ をサブミットします。EJB を呼び出すタスクを作成する手順については、セッション Bean を呼び出すタスクの作成に関するトピックを参照してください。このトピックには、スケジューラーのカレンダー機能を使用するための手順も含まれています。次の例では、ジョブ・スケジューラー EJB を呼び出す方法を示します。
// These are the import statements needed by the task
import javax.naming.*;
import com.ibm.websphere.longrun.JobScheduler;
import com.ibm.websphere.longrun.JobSchedulerHome
private JobSchedulerHome zjsHome = null;
private JobScheduler zjs = null;
public void process(TaskStatus task) ()
try{
//Ensure that the xJCL can be placed in a string, for example, by reading an xJCL
//File into a string
String xJCL = <xJCL as a string>;
//Obtain cell-level naming context
InitialContext ctxt = new InitialContext();
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL,"corbaloc:rir:/NameServiceCellRoot");
ctxt = new InitialContext(env);
//To look up the LRS EJB from the cell context in the namespace,
//The name context to the application server or cluster to which the LRS
//Application is deployed has to be provided
//Eg: "nodes/myNode/servers/myServer" or "clusters/myCluster".
String longRunningContext = <long_running_context>;
zjsHome = (JobSchedulerHome) ctxt.lookup(longRunningContext +
"/ejb/com/ibm/websphere/longrun/JobSchedulerHome");
zjs = zjsHome.create();
zjs.submitJob( xJCL );
}catch (Exception e) {
System.out.println(e.getMessage());
}
- バッチ作業をサブミットするプログラムを実行します。
『スケジューラーへのタスクのサブミット』のトピックを参照してください。