Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public abstract class JobBase : IJob,IInterruptableJob
  2. {
  3. private Thread currentThread;
  4. private ILog logger;
  5. public JobBase(ILog logger)
  6. {
  7. this.logger=logger;
  8. }
  9. public void Execute(IJobExecutionContext context)
  10. {
  11.  
  12. var thread = new Thread(()=>
  13. {
  14. try
  15. {
  16. this.ExecuteJob(context);
  17. }
  18. catch(Exception ex)
  19. {
  20. this.logger.ErrorFormat("Unhandled exception {0}",ex.ToString());
  21.  
  22. }
  23. });
  24.  
  25. thread.Start();
  26. this.currentThread = thread;
  27. this.currentThread.Join();
  28. }
  29. public abstract void ExecuteJob(IJobExecutionContext context);
  30.  
  31. public void Interrupt()
  32. {
  33. currentThread.Abort();
  34. }
  35. }
  36.  
  37. public class TestJob :JobBase
  38. {
  39. private ILog logger;
  40. public TeJob(ILog logger):base(logger)
  41. {
  42. }
  43.  
  44. public override ExecuteJob(IJobExecutionContext context)
  45. {
  46. }
  47. }
  48.  
  49. SchedulerFactory factory = new StdSchedulerFactor();
  50. Scheduler scheduler = factory.getScheduler();
  51.  
  52. scheduler.start();
  53.  
  54. scheduler.shutdown();
  55.  
  56. if(flag==true)
  57. {
  58. scheduler.start();
  59. scheduler.scheduleJob(jobDetail, simpleTrigger);
  60. }
  61. else if(flag==false)
  62. {
  63. scheduler.shutdown();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement