Search code examples
timeouthttprequesttomcat8liferay-7

Is it possible to run a long time request with Tomcat 8 and Liferay 7?


I implemented a newsletter send service in a Liferay 7 Tomcat 8 platform with an increasing number of users. Current implementation is synchronous, that is I wait the response, but it is going to be not sufficient. I would like to increment Tomcat execution timeout (and I don't know if I need to increment connectionTimeout or another Tomcat parameter) and in the meanwhile to implement an asynchronous service. Is it possible to increment Tomcat execution timeout? Any suggestion or example to do asynchronous request?


Solution

  • Is it possible? Yes. Is it a good idea? No.

    For asynchronous processing, you can look at Liferay's Scheduler to execute background jobs - the implementation depends on your requirements. You could (synchronously) create the mail tasks (e.g. determine the recipients of the mail, and the text) and store them for being sent later. In a scheduler, independent of the frontend, you can then send the mails in the background. In your frontend, you can even visualize the current queue size, so that users can continue doing their work instead of waiting for an arbitrary request to complete.

    You can use any other technique to send the mail, there's no need to go with Liferay's scheduler. It may be an external process, or anything that gets the job done. What you choose depends on your requirements. If you send from within Liferay, you'll have one set of plugins to deploy and are set, while other means might give you more flexibility in processing, e.g. write a batch job in Perl or Python, if that's your thing.