Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz in Webapplication

I have a question in scheduling jobs in web application. If we have to schedule jobs in web application we can either use java util Timer/TimerTask or Quartz(there are also other scheduling mechanism, but I considered Quartz). I was considering which one to use, when i hit the site http://oreilly.com/pub/a/java/archive/quartz.html?page=1 which says using timer has a bad effect as it creates a thread that is out of containers control in the last line. The other pages discuss Quartz and its capabilities, but I can read that Quartz also uses thread and/or threadpool to schedule tasks. My guess is that these threads are also not under the containers control

Can anybody clarify this to me Is it safe to use Quartz in my web applications without creating hanging threads or thread locking issues? Thanks in advance

like image 378
JKV Avatar asked Oct 15 '22 07:10

JKV


2 Answers

Can anybody clarify this to me Is it safe to use Quartz in my web applications without creating hanging threads or thread locking issues?

Both quartz and the JDK Timer start unmanaged threads that do not have access to Java EE contextual information, that's the biggest issue. In addition, they can use resources without the [application server] knowing about it, exist without an administrator's ability to control their number and resource usage, and impede on the application server's ability to gracefully shutdown or recover resources from failure (see Unmanaged threads).

Having that said, I didn't face hanging threads or locking issues (I guess it depends on what you're doing with them though).

If really this is a concern, consider using a JSR-237 Timer and WorkManager implementation (that works with managed thread) like Foo-CommonJ instead of quartz or JDK Timer.

like image 88
Pascal Thivent Avatar answered Oct 18 '22 10:10

Pascal Thivent


Both approaches created unmanaged threads. I use Quartz for scheduling rather than java Timer since it offer more flexability (cron expressions, for example) and it better managable.

like image 20
Seffi Avatar answered Oct 18 '22 08:10

Seffi