独自のJobFactoryを実装することで、これを行うことができます。 、そして、
public interface IJobFactory
{
/// <summary>
/// Called by the scheduler at the time of the trigger firing, in order to
/// produce a <see cref="IJob" /> instance on which to call Execute.
/// </summary>
/// <remarks>
/// <p>
/// It should be extremely rare for this method to throw an exception -
/// basically only the the case where there is no way at all to instantiate
/// and prepare the Job for execution. When the exception is thrown, the
/// Scheduler will move all triggers associated with the Job into the
/// <see cref="TriggerState.Error" /> state, which will require human
/// intervention (e.g. an application restart after fixing whatever
/// configuration problem led to the issue wih instantiating the Job.
/// </p>
///
/// </remarks>
/// <param name="bundle">
/// The TriggerFiredBundle from which the <see cref="JobDetail" />
/// and other info relating to the trigger firing can be obtained.
/// </param>
/// <throws> SchedulerException if there is a problem instantiating the Job. </throws>
/// <returns> the newly instantiated Job
/// </returns>
IJob NewJob(TriggerFiredBundle bundle);
}
あなたの仕事の工場のタイプにスケジューラのquartz.scheduler.jobFactory.typeプロパティを設定します。あなたはIJobFactoryインタフェースを実装する必要があります。参考のため
は、ここquartz.netが使用するデフォルトのジョブの工場があります:
public class SimpleJobFactory : IJobFactory
{
private static readonly ILog Log = LogManager.GetLogger(typeof (SimpleJobFactory));
/// <summary>
/// Called by the scheduler at the time of the trigger firing, in order to
/// produce a <see cref="IJob" /> instance on which to call Execute.
/// </summary>
/// <remarks>
/// It should be extremely rare for this method to throw an exception -
/// basically only the the case where there is no way at all to instantiate
/// and prepare the Job for execution. When the exception is thrown, the
/// Scheduler will move all triggers associated with the Job into the
/// <see cref="TriggerState.Error" /> state, which will require human
/// intervention (e.g. an application restart after fixing whatever
/// configuration problem led to the issue wih instantiating the Job.
/// </remarks>
/// <param name="bundle">The TriggerFiredBundle from which the <see cref="JobDetail" />
/// and other info relating to the trigger firing can be obtained.</param>
/// <returns>the newly instantiated Job</returns>
/// <throws> SchedulerException if there is a problem instantiating the Job. </throws>
public virtual IJob NewJob(TriggerFiredBundle bundle)
{
JobDetail jobDetail = bundle.JobDetail;
Type jobType = jobDetail.JobType;
try
{
if (Log.IsDebugEnabled)
{
Log.Debug(string.Format(CultureInfo.InvariantCulture, "Producing instance of Job '{0}', class={1}", jobDetail.FullName, jobType.FullName));
}
return (IJob) ObjectUtils.InstantiateType(jobType);
}
catch (Exception e)
{
SchedulerException se = new SchedulerException(string.Format(CultureInfo.InvariantCulture, "Problem instantiating class '{0}'", jobDetail.JobType.FullName), e);
throw se;
}
}
}
興味深い行は次のようになります。
return (IJob) ObjectUtils.InstantiateType(jobType);
まあ、私は同じIJobインスタンス上に保持するに興味がないんだけど、私が欲しいのは同じiMonitorのは、それぞれの新しいIJobインスタンスに注入していることです... – j040p3d20
ストアJobDataMapであなたの「モニター」への参照独自のJobFactoryを実装することもできます。 – Dmitry
'StatefulJob'インターフェースは非推奨です... http://quartz-scheduler.org/documentation/quartz-2.x/new-in-quartz-2注釈を使うことをお勧めします – Jaider