How to send mail within a servlet using threads or executor service? [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to send mail within a servlet using threads or executor service? [closed]



I want to send mail based on if a condition



ServletMail.java


//somecodes

//this code should code should be executed in background(by threads or something)

if(cond1)

sendmail(firstcond)



else

sendmail(secondcond)



//requestdispatcher



Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





This site is for narrowly-focused questions on a specific technical issue. This is much too broad. Servlet, mail, and executors have been covered in many other questions and answers.
– Basil Bourque
Aug 13 at 9:10





1 Answer
1



You can use ExecutorService executorService = Executors.newFixedThreadPool(threadNumber); . There threadNumber is concurrent use threads.


ExecutorService executorService = Executors.newFixedThreadPool(threadNumber);



You can use it like this


if(cond1)
executorService.execute(new Runnable()
@Override
public void run()
sendmail(firstcond);

);
else
executorService.execute(new Runnable()
@Override
public void run()
sendmail(secondcond);

);



Do not forget put this executorService.shutdown(); to web server shutdown listener.


executorService.shutdown();





Can this snippet be used within servlet?
– Praveenkumar
Aug 13 at 9:20





Ofcourse! Above servlet declare public static ExecutorService executorService = Executors.newFixedThreadPool(threadNumber); after it is you can use it.
– Dilshod Tadjiev
Aug 13 at 9:27





thanku that worked for me
– Praveenkumar
Aug 23 at 6:37





welcome! Good luck
– Dilshod Tadjiev
Aug 23 at 9:53

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard