Note that there are some explanatory texts on larger screens.

plurals
  1. POjava run only one instance at a time
    primarykey
    data
    text
    <p>I am using Java(Servlet,JSP) to develop a web application.</p> <p>I have a class which send emails.</p> <p>Class looks like:</p> <pre><code>public class EmailSender { String SendEmail(String from,Session session,String To,String CC, String BCC, String Subject,String Body) { //Actual code for sending emails } } </code></pre> <p><code>EmailSender</code> class is called from another class:</p> <pre><code>public class InvokeSender { public InvokeSender(String dbFileName) { //get emails from database for sending who has STATUS='NOTSENT' //statements to get all required parameter to pass to SendEmail() EmailSender sender = new EmailSender(); String msg = sender.SendEmail(fromEmail,session,To,CC,BCC,SUBJECT,BODY); } } </code></pre> <p>And <code>InvokeSender</code> is called from servlet when the used clicks the button.</p> <p>When user clicks on button the InvokeSender is called, which takes emails to be send from database and forms them and then pass those parameters to <code>SendEmail()</code> of <code>EmailSender</code> class.</p> <p>I want only one instance of <code>InvokeSender</code> to run at a time to avoid same emails going twice if the button is pressed twice. How this can be handled? Will <code>multithreading</code> useful in this case? </p> <p>Any suggestion will be appreciated.</p> <p><strong>Update1</strong> I can't disable the button after user clicks it. Because if user refresh the page then that button will be enabled by default.</p> <p><strong>Update2</strong> First user selects customers, template etc. for sending emails and after that email parameters are stored in database. <code>InvokeSender</code> class get all emails to be sent. Number of emails to be sent can't be predicted. It can be 1 or 500 or more than that. I want only one instance of <code>InvokeSender</code> to run until previous instance is completed sending emails. Functionality (Button to generate and send email) will be exposed to 5-7 users.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload