0

When you want to launch scripts (.sh,jar,.py,.pl...) running more than some hours by a simple click on a user interface(for example a nice jsf page). What are the best methods to throw process. Running.exec() method , the use of Threads or something else ? Thanks.

ZheFrench
  • 1,164
  • 3
  • 22
  • 46
  • Why not have a separate daemon thread running as a process on the server that waits for a signal to start. When it receives a notification (using JMS?) to start, it does the background work. – mttdbrd Apr 26 '14 at 15:30

1 Answers1

1

Definitely do not use long running threads inside a Java web app. Send a message with the task (ideally via a queue (for example rabbitmq)) to a separate application with its own thread pool, which will then handle independently the long running tasks requested by the webapp users.

If your system does not have a messaging system installed, and you find the overhead of managing one too high, and you are already using some sql or no-sql or whatever storage, you can probably adapt this storage to also be used for communication between the webapp and your new separate long requests runner app.

yotsov
  • 775
  • 5
  • 11
  • Yep i'm actually using a job scheduler - Torque - which controls job execution on a cluster. On another hand for a short process (sending an e-mail) would you prefer a thread ? – ZheFrench Apr 26 '14 at 19:52
  • Even for something as quick as sending an email, I would delegate the task to another application if I have control over the deployment environment. Having more than one thread pool management per application is to be avoided, and a web server already has its own arbitrarily intricate thread pool. – yotsov Apr 26 '14 at 20:10