java - How to use Multithreading concept in Spring MVC for subsequent operations -
i send email , update activity logs after updating profile in web application. sending mails , updating activity logs, use thread profile update response can sent client , subsequents operations can taken care threads. please suggest implementation.
there numerous ways achieve this, fact it's spring mvc application irrelevant.
if you're using java 8 can call upon executor service give thread pool:
string emailaddress = //get email address... executorservice executorservice = executors.newsinglethreadexecutor(); executorservice.submit(() -> { emailservice.sendnotification(emailaddress); });
pre-java 8:
final string emailaddress = ""; thread thread = new thread(new runnable() { @override public void run() { emailservice.sendnotification(emailaddress); } }); thread.start();
if you're creating more complex application should possibly using message queue (activemq good). allows more control , visibility , scales add more asynchronous tasks, means won't starve application server of threads if there lots of registrations @ same time.
Comments
Post a Comment