Quartz.NET 远程处理 - 调度程序已存在
我正在创建一个使用 Quartz.NET 的应用程序,该应用程序在 Windows 服务中使用。还有一个用 ASP.NET 编写的管理后端,管理员可以在其中添加作业并监视调度程序的状态。然而,我在 ASP.NET 后端遇到问题。
连接是在 Global.asax 文件中建立的,该文件一开始似乎工作正常 - 当用户登录到主仪表板时,它工作正常。问题是当用户单击不同的页面时,它会说调度程序“schedService”已经存在。
这是我的 Windows 服务代码:
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "schedService";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = threadcount;
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.jobStore.misfireThreshold"] = "60000";
properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.useProperties"] = "false";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
//
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";
//
// if running MS SQL Server we need thisl
properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
// config file
properties["quartz.dataSource.default.connectionString"] = connection;
properties["quartz.dataSource.default.provider"] = "SqlServer-20";
ISchedulerFactory schedService = new StdSchedulerFactory(properties);
IScheduler sched = schedService.GetScheduler();
ASP.NET Global.asax 代码:
public static IScheduler Sched()
{
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "schedMaintenanceService";
properties["quartz.scheduler.proxy"] = "true";
properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
return sched;
}
然后我在每个 ASP.NET 页面中使用它:
public static IScheduler sched = Project.Global.Sched();
I am creating an application that uses Quartz.NET, which is utilised within a Windows service. There is also an administration backend written in ASP.NET, where administrators can add jobs and monitor the state of the scheduler. I am however having issues with the ASP.NET backend.
The connection is made in the Global.asax file, which seems to work at first - when the user logs on to the main dashboard, it works fine. The problem is when the user clicks onto a different page, where it then says the scheduler 'schedService' already exists.
Here is my Windows Service code:
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "schedService";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = threadcount;
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.jobStore.misfireThreshold"] = "60000";
properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.useProperties"] = "false";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
//
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";
//
// if running MS SQL Server we need thisl
properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
// config file
properties["quartz.dataSource.default.connectionString"] = connection;
properties["quartz.dataSource.default.provider"] = "SqlServer-20";
ISchedulerFactory schedService = new StdSchedulerFactory(properties);
IScheduler sched = schedService.GetScheduler();
ASP.NET Global.asax code:
public static IScheduler Sched()
{
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "schedMaintenanceService";
properties["quartz.scheduler.proxy"] = "true";
properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
return sched;
}
Then I use this in each ASP.NET page:
public static IScheduler sched = Project.Global.Sched();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你应该将 IScheduler 编写为单例
you should write your IScheduler as a singleton
我对“调度程序已经存在”有类似的问题。我创建了一个单例类,并且能够解决我的问题。
如果任何人都可以使用的话,单例代码看起来像这样。该锁是为了避免以前当有更多线程尝试同时获取同一实例时出现的问题。
I had a similar issue with the "scheduler already exists". I created a singleton class and I was able move past my issue.
The singleton code looks like this if anybody can use it. The lock is to avoid the issue from before when having more threads trying to get the same instance at once.
我找到了另一个解决方案。通过给每个调度程序一个不同的名称,我能够解决这个问题。我发现这是比单例更好的解决方案。
I found another solution. By giving each scheduler a different name I was able to work around the issue. I find this a better solution than the singleton one.