आप अपना खुद का जॉबफैक्टरी लागू करके ऐसा कर सकते हैं।
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 इंटरफ़ेस को लागू करना होगा।
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;
}
}
}
दिलचस्प लाइन है:
संदर्भ के लिए, डिफ़ॉल्ट काम कारखाने कि quartz.net का उपयोग करता है
return (IJob) ObjectUtils.InstantiateType(jobType);
ठीक है, मैं एक ही IJob उदाहरण पकड़े में कोई दिलचस्पी नहीं हूँ, क्या मैं चाहता हूँ एक ही IMonitor प्रत्येक नए IJob उदाहरण में इंजेक्ट किया है करने के लिए है ... – j040p3d20
स्टोर अपने JobDataMap में 'मॉनिटर' के संदर्भ में या अपने स्वयं के जॉब फैक्टरी को लागू करें। – Dmitry
'स्टेटफुल जोब' इंटरफेस को बहिष्कृत कर दिया गया है ... यह एनोटेशन का उपयोग करने की सिफारिश करता है http://quartz-scheduler.org/documentation/quartz-2.x/new-in-quartz-2 – Jaider