I am designing/developing a web application that will ultimately deploy as a WAR to Tomcat. One of the features of this application will be the ability for users to upload images to our server and edit them (generate thumbnails, etc.). Under the hood we will be using ImageMagick
and its Java adaptor library IM4Java
.
Initial prototypes have shown that ImageMagick takes some time to "warm up" on our servers every time we re-deploy the application. This has prompted us to consider one of two possibilities, either:
- Create an
ImageService.war
web service that deploys alongside the primary app and basically handles all calls toIM4Java
under the hood (exposes, say, a RESTful service and just runs ImageMagick when it receives a request; the primary web app cann then find the edited file(s) on the same local file system); or - Just create a
Thread
subclass (i.e.ImageServiceThread
), kick it off and run it at deploy-time, and make sure it gets shut down when Tomcat undeploys the app
These two prospects got me thinking about this problem in a more abstract sense: when should one simply delegate work out to a separate thread, and when is it appropriate to make a full-blown, separate app (in our case a WAR)?
Our primary app will be the only user of this "Image Service", which has me thinking a separate WAR is overkill and unnecessary. But I've never dealt with threading inside of Tomcat before and am not sure if it is possible to spawn and kill a thread so that its lifecycle coincides with that of the primary/main app thread.
What sort of factors should be considered as part of such a decision? Thanks in advance.