ラベル quartz の投稿を表示しています。 すべての投稿を表示
ラベル quartz の投稿を表示しています。 すべての投稿を表示

2009年11月5日木曜日

groovyとPostgreSQLとquartzの組み合わせで、トリガー情報を表示する

groovyとPostgreSQLとquartzの組み合わせで、トリガー情報を表示するには、以下のコードを実行します。

import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
//sf = new StdSchedulerFactory()
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

// トリガー情報の表示
trg = sched.getTrigger("trigger1", "group1")
if( trg != null ){
println("name:" + trg.name)
println("full name:" + trg.fullName)
println("group:" + trg.group)
println("job group:" + trg.jobGroup)
println("job name:" + trg.jobName)
println("previous fire time:" + trg.previousFireTime)
println("next fire time:" + trg.nextFireTime)
}
sched.shutdown(true)



設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false

2009年10月30日金曜日

groovyとPostgreSQLとquartzの組み合わせでジョブ情報を表示する

groovyとPostgreSQLとquartzの組み合わせでジョブ情報を表示するには、以下のコードを実行します。


import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
//sf = new StdSchedulerFactory()
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

// ジョブ情報の表示
job = sched.getJobDetail("job1", "group1")
if( job != null ){
println("name:" + job.name)
println("full name:" + job.fullName)
println("group:" + job.group)
println("job class:" + job.jobClass.name)
}
sched.shutdown(true)


設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false

2009年10月25日日曜日

groovyとPostgreSQLとquartzの組み合わせでトリガーを一覧表示する

groovyとPostgreSQLとquartzの組み合わせでトリガーを一覧表示するには、以下のコードを実行します。


import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
//sf = new StdSchedulerFactory()
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

trgGroupNames = sched.getTriggerGroupNames()
println("total number of trigger group names:" + trgGroupNames.length)
for( trgGroupName in trgGroupNames ){
println("trigger group name:" + trgGroupName)
trgNames = sched.getTriggerNames(trgGroupName)
// トリガーを列挙
for( trgName in trgNames ){
println("trigger name:" + trgName)
}
}

sched.shutdown(true)


設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false

2009年10月23日金曜日

groovyとPostgreSQLとquartzの組み合わせでcron風にJobをスケジューリングする

groovyとPostgreSQLとquartzの組み合わせでcron風にJobをスケジューリングするには、以下のコードを実行します。

ジョブコード(HelloQuartzJob.groovy)

import org.quartz.*

class HelloQuartzJob implements Job
{
// ジョブ実行メソッド
void execute(JobExecutionContext context)
throws JobExecutionException
{
println("Hello, Quartz!" + new Date())
}
}


quartz設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false


quartzスタンドアロン実行用コード(StartQuartz.groovy)(exitと入力すると終了する)

import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
sf = new StdSchedulerFactory("./myquartz.properties")
//sched = sf.getScheduler()

// スケジューラを開始
//sched.start();

server = new QuartzServer()
server.serve(sf, true)


ジョブスケジューリング用コード(RegisterHelloQuartzJob.groovy)

import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

// ジョブ定義
JobDetail job = new JobDetail(
// ジョブ名
"job1",
// グループ名
"group1",
// ジョブクラス
HelloQuartzJob.class
)

// cron風のtrigger
trigger = new CronTrigger(
// トリガー名
"trigger1",
// グループ名
"group1",
// ジョブ名
"job1",
// グループ名
"group1",
// 月曜日から金曜日の21時
"0 0 21 ? * MON-FRI");
sched.scheduleJob(job, trigger)

sched.shutdown(true)


実行するときは、コマンドプロンプトから
groovy StartQuartz.groovyでスタンドアロンで実行させ、
別のコマンドプロンプトからgroovy RegisterHelloQuartzJob.groovyで
ジョブを登録します。

2009年10月19日月曜日

groovyとPostgreSQLとquartzの組み合わせでトリガーグループを一覧表示する

groovyとPostgreSQLとquartzの組み合わせでトリガーグループを一覧表示するには、以下のコードを実行します。


import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
//sf = new StdSchedulerFactory()
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

// トリガーグループ名を列挙
trgGroupNames = sched.getTriggerGroupNames()
println("total number of trigger group names:" + trgGroupNames.length)
for( trgGroupName in trgGroupNames ){
println("trigger group name:" + trgGroupName)
}

sched.shutdown(true)


設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false

2009年10月14日水曜日

groovyとPostgreSQLとquartzの組み合わせでジョブを一覧表示する

groovyとPostgreSQLとquartzの組み合わせでジョブを一覧表示するには、以下のコードを実行します。


import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
//sf = new StdSchedulerFactory()
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

jobGroupNames = sched.getJobGroupNames()
println("total number of job group names:" + jobGroupNames.length)
for( jobGroupName in jobGroupNames ){
println("job group name:" + jobGroupName)
// ジョブを取得
jobNames = sched.getJobNames(jobGroupName)
for( jobName in jobNames ){
println("job name:" + jobName)
}
}
sched.shutdown(true)


設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false

2009年9月29日火曜日

groovyとPostgreSQLとquartzの組み合わせでJobを作成する

1.quartzの設定
http://www.opensymphony.com/quartz/download.actionから
quartz-1.6.5.zipをダウンロードして、解凍。
quartz-all-1.6.5.jarをgroovyのlibディレクトリへコピー。
quartzのlib/coreのcommons-collections-3.2.jarをgroovyのlibディレクトリへコピー。quartzのlib/optionalのcommons-pool-1.3.jarをgroovyのlibディレクトリへコピー
quartzのlib/optionalのcommons-dbcp-1.2.2.jarをgroovyのlibディレクトリへコピー

postgresのJDBCドライバーもgroovyのlibディレクトリへコピーしておく。

PostgreSQLで以下のコマンドを実行してDB作成。
CREATE DATABASE quartz
WITH OWNER = postgres
ENCODING = 'UTF8'
LC_COLLATE = 'Japanese, Japan'
LC_CTYPE = 'Japanese, Japan'
CONNECTION LIMIT = -1;

quartzのdocs/dbTables/tables_postgres.sqlを実行。

2.以下のように設定ファイルを作成。
myquartz.properties

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false


2.以下のようにJobインターフェイスを実装するクラスを作成

import org.quartz.*

class HelloQuartzJob implements Job
{
// ジョブ実行メソッド
void execute(JobExecutionContext context)
throws JobExecutionException
{
println("Hello, Quartz!" + new Date())
}
}


3.作成したジョブクラスをJobDetailとTriggerに関連付けて実行します。

import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

// 次の分の0秒にスケジュール
Date runTime = TriggerUtils.getEvenMinuteDate(new Date())
JobDetail job = new JobDetail(
// ジョブ名
"job1",
// グループ名
"group1",
// ジョブクラス
HelloQuartzJob.class
)

// 指定した時間に実行するトリガー
trigger = new SimpleTrigger(
// トリガー名
"trigger1",
// グループ名
"group1",
// 実行時間
runTime
)

// ジョブをスケジュール
sched.scheduleJob(job, trigger)

// スケジューラを開始
sched.start();

try {
// ジョブ実行をするために2分待ち
Thread.sleep(120L * 1000L)
}
catch(Exception ex){}

// 終了
sched.shutdown(true)

2009年9月26日土曜日

groovyとPostgreSQLとquartzの組み合わせでジョブグループを一覧表示する

groovyとPostgreSQLとquartzの組み合わせでジョブグループを一覧表示するには、以下のコードを実行します。


import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
//sf = new StdSchedulerFactory()
sf = new StdSchedulerFactory("./myquartz.properties")
sched = sf.getScheduler()

// ジョブグループ名を列挙
jobGroupNames = sched.getJobGroupNames()
println("total number of job group names:" + jobGroupNames.length)
for( jobGroupName in jobGroupNames ){
println("job group name:" + jobGroupName)
}
sched.shutdown(true)


設定ファイル(myquartz.properties)

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

# データソースの設定
org.quartz.dataSource.QuartzDS.driver = org.postgresql.Driver
org.quartz.dataSource.QuartzDS.URL = jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.QuartzDS.user = postgres
org.quartz.dataSource.QuartzDS.password = postgres
org.quartz.dataSource.QuartzDS.maxConnections = 10
org.quartz.dataSource.QuartzDS.validationQuery = select 1

# JDBC JobStore設定
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = QuartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = false
org.quartz.jobStore.acquireTriggersWithinLock = false

2009年9月24日木曜日

groovyでquartzのジョブを作成する

1.quartzを使用するための設定
http://www.opensymphony.com/quartz/download.actionから
quartz-1.6.5.zipをダウンロードして、解凍。
quartz-all-1.6.5.jarをgroovyのlibディレクトリへコピー。
quartzのlib/coreのcommons-collections-3.2.jarをgroovyのlibディレクトリへコピー。

2.以下のようにJobインターフェイスを実装するクラスを作成

ジョブの実装(HelloQuartzJob.groovy)

import org.quartz.*

class HelloQuartzJob implements Job
{
// ジョブ実行メソッド
void execute(JobExecutionContext context)
throws JobExecutionException
{
println("Hello, Quartz!" + new Date())
}
}


3.作成したジョブクラスをJobDetailとTriggerに関連付けて実行します。

ジョブの登録と実行

import org.quartz.*
import org.quartz.impl.*

// スケジューラ取得
sf = new StdSchedulerFactory()
sched = sf.getScheduler()

// 次の分の0秒にスケジュール
Date runTime = TriggerUtils.getEvenMinuteDate(new Date())
JobDetail job = new JobDetail(
// ジョブ名
"job1",
// グループ名
"group1",
// ジョブクラス
HelloQuartzJob.class
)

// 指定した時間に実行するトリガー
trigger = new SimpleTrigger(
// トリガー名
"trigger1",
// グループ名
"group1",
// 実行時間
runTime
)

// ジョブをスケジュール
sched.scheduleJob(job, trigger)

// スケジューラを開始
sched.start();

try {
// ジョブ実行をするために2分待ち
Thread.sleep(120L * 1000L)
}
catch(Exception ex){}

// 終了
sched.shutdown(true)