I am new to Quartz and I am going to write jobs that require a lot of services/dependencies.
Would it make sense to create a Spring context in the job execute method (so for any new job there will a new Spring context) or is it better to create a unique Spark context before the jobs get created and inject services for any new job?
Thank you.
That depends on your requirements and preferences.
If your job only starts at a determined time of the day, something like everyday at 3:00 am. Then it's not important that your spring context takes to starts a couple of minutes. In this case or any other case where it's not important the time until the context is up and running, I suggest you to start the context every time a job is started. It has no sense to keep a context up and running along the hole day if you only will use it a little part of it.
However, you can have a lot of jobs. And probably it does not matter the time they take to be up and running. But if they are many, it will use a lot of memory starting a new context for every job. So, in this case I would recommend you to init a unique spring context. So you can optimize the memory of your server.
Other case, would be that the start up time matters. In this case, it's better to have the spring context up and running, so you can use it, every time you need almost immediately.