Setting up ExecutorService to manage a group in a bulk mailer

I'm trying to write a bulk mailer for a scheduling application which deals with groups of people. What I'm trying to do is to takes a collection and split into the individuals and then use newCachedThreadPool() to build and send the message in a separate thead so that the mailer doesn't affect the rest of the application. I've got the body being built successfully but instead of getting it to send individually, it is sending multiple times to the same address, so if I have five addresses, it can send five copies of the same mail to the last address five times and ignore the first four. I'm also trying to ensure that it has only one address in the TO field as well (which was what was happening in the non-concurrent version) but the pool appears to want to add all the addresses into one to field when it does send.
  private Calendar cal1;
  private String sender;
  private String recip;
  private String subject1;
  private ArrayList<String> recip1;
  class sendMail implements Runnable {
       public sendMail (Calendar cal1,
                          String sender,
                          ArrayList<String> recip1,
                          String subject1) {
          public void run() {
               try {
                      Iterator it = recip1.iterator();
                      while (it.hasNext()){ 
                                String to = it.next().toString();
                                     msg.setFrom(new InternetAddress(sender));
                                     msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
                                    msg.setSubject(subject1);
                                    msg.setSentDate(new Date());
                                    msg.setContent(content, "text/calendar");
                                   msg.setText("Test calendaring mail");
                       Transport tr = sess.getTransport(config.getProtocol());
                       tr.connect();
                       tr.sendMessage(msg, msg.getRecipients(javax.mail.Message.RecipientType.TO));
                } catch (Exception e) {
                        e.printStackTrace();
  public boolean mailEntity(Calendar cal,
                            String originator,
                            Collection<String>recipients,
                            String subject) throws CalFacadeException {
       cal1 = cal;
       sender = originator;
       subject1 = subject;
         recip1 = new ArrayList<String>();
       pool = Executors.newCachedThreadPool();
       if (debug) {
         debugMsg("mailEntity called with " + cal);
      getConfig();
      if (config.getDisabled()) {
         return false;
      try {
          String domain = "bar.com";
           Iterator it = recipients.iterator();
             while (it.hasNext()) {
                  String recip = it.next().toString();
                  debugMsg("String is " + recip);
                  String[] splitting = recip.split("@");
                  String split = splitting[1];
                  debugMsg("Split string is " + split);
                  if (split.equals(domain)) {
                  log.info("Recipient is " + recip);
                     try {
                        conn = DriverManager.getConnection("connection");
                        stmt = conn.createStatement();
                        rs = stmt.executeQuery ("SELECT DISTINCT username FROM listname");
                        while (rs.next()) {
                         String groupmember = rs.getString(1);
                         recip1.add(groupmember);
                            if (originator == null) {
                               sender = config.getFrom();
                            if (subject == null) {
                                  subject1 = config.getSubject();
                          pool.execute(new sendMail(cal1, sender, recip1, subject1));
                    rs.close();
                    stmt.close();
                 }catch (Exception e) {
                    e.printStackTrace();
                  } finally {
                    if (conn != null) {
                        conn.close();
                } else {
                     recip1.add(recip);
                     if (originator == null) {
                        originator = config.getFrom();
                     if (subject == null) {
                            subject1 = config.getSubject();
                     pool.execute(new sendMail(cal1, sender, recip1, subject1));
           }//end while
               return true;
                } catch (Throwable t) {
                  if (debug) {
                      t.printStackTrace();
             throw new CalFacadeException(t);
  }I'd be grateful for any pointers.

Hi BaroqueThoughts,
I've pasted your code into an IDE and it looks like that the sendMail class is a inner class, with the listed variables as fields of the parent class
  private Calendar cal1;
  private String sender;
  private String recip;
  private String subject1;
  private ArrayList<String> recip1;
  class sendMail implements Runnable I notice in the run() method the field recip1 is used, the scope of this variable will be of the parent class not the inner class (sendMail). This means that all instances of sendMail will access the same list, which being an ArrayList alone is not really suited for multithreaded usage.
public sendMail (Calendar cal1, String sender,
ArrayList<String> recip1, String subject1) {
}The above constructor does nothing with the passed in values, none of the variables are stored in a field of the class. By coincidence there appear to be variables with the same names and types declared in the parent class (which the inner class can access) so there's no compilation problems.
pool.execute(new sendMail(cal1, sender, recip1, subject1));If you hadn't guessed by now that means the variables your entering into the sendMail() constructor during the mailEntity() are not being used, the variables held in the parent class are the ones being used.
In short, I'd say that the problems your experiencing are most likely due to concurrent accessing of fields.
Pointer: Refactor the Runnable class into it's own file and so making it a public class, this will should all the fields that you will need to control access to or relocate (e.g. synchronize / volatile / use different API class/ factor out into runnable class).

Similar Messages

  • Can't manage distribution group from Outlook with Exchange 2010 or Exchange 2013 mailbox

    Hi All,
    In my environment we are using exchange 2010 that contains the distribution groups which has been migrated from exchange 2003 environment .On that one of the distribution group is having an problem for the user who had an access to manage DL'S via outlook
    but he can't able to manage it.When we add the new user to manage same DL and the new user tries to manage the DL via outlook it happens without any issues. 
    issue occurs only for the user who has already have the manage access permission on the DL where the group was on exchange 2003 before migrated to exchange 2010.
    Reffered blog : http://support2.microsoft.com/kb/2586832?wa=wsignin1.0
    We have done all the settings defined on the above mentioned link but still we are facing the issue.
    In addition to that , we have forcefully upgraded the DL too by using the below mentioned command.
    set-distributiongroup -identity "name of the problematic DL" -forceupgrade
    Please all of you provide your valuable suggestions to overcome this issue .
    Error message :
    Regards
    S.Nithyanandham
    Thanks S.Nithyanandham

    Hi S.Nithyanandham,
    From your description, I would like to verify if the problematic manager user is a member of security group. If yes, this issue will occur. In Exchange 2010, distribution groups can't be managed by groups, only individual users can manage groups. But in
    Exchange 2003, it is possible to use groups to manage a distribution group.
    For more information, here is a blog for your reference.
    How to manage groups with groups in Exchange 2010
    http://blogs.technet.com/b/exchange/archive/2011/05/04/how-to-manage-groups-with-groups-in-exchange-2010.aspx
    Hope this can be helpful to you.
    Best regards,
    Amy Wang
    TechNet Community Support

  • Find the Manager for Group

    If this isn't a good place to ask this question I applogize in adavance if you could provide a link to the correct area I should ask/post this I would appreciate it. Otherwise...
    The end goal is to fill in the Managedby atribute for a lot of secuirty groups with a correct manager. I have a list of a 2100 groups and I have a data share that has like 10 petabytes of data in 3000 different directories, roughly. The point is there is
    a lot. At this point I'm just trying to identify who should be the manager for group.
    I'm trying to figure out the best way to approach this any and all advice/suggestions is apprecited. Even it is go pound sand, newby...hopefully not but I'll understand if it is :-)
    Found
    this searching
    Thanks in Adavance

    Fair enough...Sorry for wasteing your time, but thank you for your help
    Thanks in Adavance
    You are not wasting anyone's time it is just that there is no way to answer your question.  These decisions are based on your organization.  Scripts cannot decide who manages who.  You need to get with your management and implement an org
    chart.  The org chart gets directly tied to groups.  It starts with the org chart.  Each position gets a group and the manager or exec is the owner of the group.
    In most companies this may be delegated since so many managers and execs are computer illiterate.  The delegate becomes the group manager and manages resource allocation through group membership.
    This is Active Directory deployment 101.  I recommend contacting a certified consultant to help you set this up.  It is fundamental and critical.  I cannot understand how you can have a large AD deployment without having a formal design document. 
    It probably exists but those that know it have been let go to save money.  Now you are lost in limbo.
    Do more research.  Ask a lot of questions.  Be a detective and see if you can find the original documents.  If you succeed you will be a hero.
    ¯\_(ツ)_/¯

  • Company code set up for material management

    Experts,
    When I try to create sales order error is coming Comany code IN02 not set up for material management. In OMSY I have changed current and previous accordingly.
    Resolve this.
    Thanks & regards,
    Supriyo

    Mr. Naren,
    This is not a reply from an expert. I am practicing in IDES on my own in my house. I try to do all things in configuration on my own with the available study material.
    Whenever I get any error first I try myself whether it takes 2/3 days to get it resolved. Then I go to Google for further search help. Finally I go to SCN.
    Thanks & regards,
    Supriyo

  • The OMS is not set up for Enterprise Manager Security

    Hi, I'm trying to add an agent to grid control and its not connecting with the management server because i cant secure it...
    bash-2.05$ ../../bin/emctl secure agent <password>
    Oracle Enterprise Manager 10g Release 3 Grid Control 10.2.0.3.0.
    Copyright (c) 1996, 2007 Oracle Corporation. All rights reserved.
    Agent is already stopped... Done.
    Securing agent... Started.
    Requesting an HTTPS Upload URL from the OMS... Failed.
    The OMS is not set up for Enterprise Manager Security.
    i have tried this on two seperate servers, both do the exact same thing. However, on my repository server where the OMS is housed, i can secure the agent no problem. Does anyone know what the problem could be? My OMS is on a Linux (SuSE 10.2) 32-bit machine.
    heres the emdctl.trc on the agent machine:
    2007-07-11 11:00:20 Thread-1 ERROR main: nmectla_agentctl: Error connecting to http://cbldb3:3872/emd/main/. Returning status code 1
    2007-07-11 11:00:21 Thread-1 WARN http: snmehl_connect: connect failed to (cbldb3:3872): Connection refused (error = 239)
    2007-07-11 11:00:21 Thread-1 ERROR main: nmectla_agentctl: Error connecting to http://cbldb3:3872/emd/main/. Returning status code 1
    2007-07-11 11:00:21 Thread-1 WARN http: snmehl_connect: connect failed to (cbldb3:3872): Connection refused (error = 239)
    2007-07-11 11:00:21 Thread-1 ERROR main: nmectla_agentctl: Error connecting to http://cbldb3:3872/emd/main/. Returning status code 1
    2007-07-11 11:00:22 Thread-1 WARN http: snmehl_connect: connect failed to (cbldb3:3872): Connection refused (error = 239)
    2007-07-11 11:00:22 Thread-1 ERROR main: nmectla_agentctl: Error connecting to http://cbldb3:3872/emd/main/. Returning status code 1
    2007-07-11 11:05:10 Thread-1 WARN http: snmehl_connect: connect failed to (cbldb3:3872): Connection refused (error = 239)
    2007-07-11 11:05:10 Thread-1 ERROR main: nmectla_agentctl: Error connecting to http://cbldb3:3872/emd/main/. Returning status code 1
    2007-07-11 11:10:08 Thread-1 WARN http: snmehl_connect: connect failed to (cbldb3:3872): Connection refused (error = 239)
    2007-07-11 11:10:08 Thread-1 ERROR main: nmectla_agentctl: Error connecting to http://cbldb3:3872/emd/main/. Returning status code 1
    bash-2.05$ lsof | grep 3872
    bash-2.05$
    seems to be failing the connect but nothing is running on the port so i'm not sure why
    Thanks in advance
    Message was edited by:
    user581869

    some further information and hopefully someone can help me...
    I went to the OMS binary folder (fmc45712:$OMS_HOME/bin) and executed the following commands...
    $OMS_HOME/opmn/bin/opmnctl stopall
    $OMS_HOME/bin/emctl stop oms
    $OMS_HOME/bin/emctl secure oms
    $OMS_HOME/bin/emctl start oms
    $OMS_HOME/opmn/bin/opmnctl startall
    then i go to $AGENT_HOME on the OMS machine (fmc45712:$AGENT_HOME/bin) and execute..
    $AGENT_HOME/bin/emctl status agent -secure
    Oracle Enterprise Manager 10g Release 3 Grid Control 10.2.0.3.0.
    Copyright (c) 1996, 2007 Oracle Corporation. All rights reserved.
    Checking the security status of the Agent at location set in /opt/oracle/OracleHomes/agent10g/sysman/config/emd.properties... Done.
    Agent is secure at HTTPS Port 3872.
    Checking the security status of the OMS at http://fmc45712:4889/em/upload/... Done.
    OMS is secure on HTTPS Port 1159
    I then to go the server i deployed the agent on that i want to get communicating wtih my OMS...
    $AGENT_HOME/bin/emctl status agent -secure
    Oracle Enterprise Manager 10g Release 3 Grid Control 10.2.0.3.0.
    Copyright (c) 1996, 2007 Oracle Corporation. All rights reserved.
    Checking the security status of the Agent at location set in /u101/em/agent10g/sysman/config/emd.properties... Done.
    Agent is unsecure at HTTP Port 3872.
    Checking the security status of the OMS at http://fmc45712:4889/em/upload/... Done.
    OMS is running but has not been secured. No HTTPS Port available.
    same command, different computer, but on the same network, and it just doesn't work. The OMS is on Linux x86 and the agent on the alternate computer is on HP-UX. If anyone has any help it'd be much appreciated.

  • Setting the header of a Column group in a Advanced table dynamically

    Hi All,
    There is a requirement to set the Header of a column group in a Advanced table dynamically by fetching the values from a view attribute.
    Code :
    OAAdvancedTableBean spiderTbl1 ;
    Problem:
    It is not able to set the value for the header inspite of getting the handle of the bean.
    Analysis:
    the same piece of code works for
    1) Setting the text of the advanced table
    2) Setting the header of a column in a column group
    Please let me know if there is anything more that needs to be done for setting the prompt of a column group header.
    Thanks in advance!

    I have posted it without giving the complete code by mistake. Below is the code:
    OAAdvancedTableBean spiderTbl1 ;
    OASortableHeaderBean spiderHdr1;
    spiderTbl1 = (OAAdvancedTableBean)webBean.findChildRecursive("SpiderCatTbl1RN");
    if (spiderTbl1!=null){
    spiderHdr1= (OASortableHeaderBean)spiderTbl1.findChildRecursive("AnalogHdr");
    if (spiderHdr1!=null) {
    spiderHdr1.setAttributeValue(OAWebBeanConstants.PROMPT_ATTR,
    new OADataBoundValueViewObject(spiderHdr1,
    "SpiderCategory1",
    "ProjRegPVO1"));
    }

  • How to save the setting in MDM import manager?

    How to save the setting in MDM import manager? After I configure all things in MDM import manager, I try to save the setting, let's say, saved map name is " Test002", and then I export this map into desktop. After that, I logon Import manager again, and import this map file, system show me the same thing that I have to configure it again, because nothing was changed, what I configured before, were all disappeared.

    Hi Alfred ,
    are You not saving this map in Import Manager ? Import Manager itslef saves the map and remember it . Exporting map is only for backup .
    Pls make changes and save the map . Exit and relogin . then see the map . It should be there . Pls let us know the result .
    - An

  • The iPad doesn't seem to want to set up an email for a "group" in my contacts. On my iMac, when I type the name of a group, the email addresses of everyone in the group appear in the "To" line of a new message. Not so with the iPad. Help?

    The iPad doesn't seem to want to set up an email for a "group" in my Contacts. When I type the name of a group in the "To:" line of a new message on my iMac, all the email addresses of the group automatically appear. Not so with my iPad. Help?

    Apparently Groups are not supported in the Mail App on the iPad. Read this thread and see Michael Morgan's post for a workaround.
    https://discussions.apple.com/message/13084823#13084823

  • Please provide the patch set for Oracle Enterprise Manager Grid Control 10

    Hi,
    please provide the patch set for Oracle Enterprise Manager Grid Control 10.2.0.1 and 10.2.0.5 for AIX 5.3
    patch set for Oracle Enterprise Manager Grid Control for 11.2.0.2 OS AIX 5.3
    Thanks,
    Vishal Hande.

    user12009184 wrote:
    Hi,
    please provide the patch set for Oracle Enterprise Manager Grid Control 10.2.0.1 and 10.2.0.5 for AIX 5.3
    patch set for Oracle Enterprise Manager Grid Control for 11.2.0.2 OS AIX 5.3
    Thanks,
    Vishal Hande.you must obtain all patches directly from
    http://support.oracle.com

  • How to set fill, stroke & color to a group

    First of all, I must say I'm a complete beginner in Javascript so please have patience with me.
    What I'm trying to do is to set a lot of groups to specific fill, stroke & color using a function.
    var docRef = app.activeDocument;
    var Reg = docRef.swatches["[Registration]"].color;
    var mm = 2.834645;
    var lineWidth=0.12*mm;
    group1.stroked=true;
    group1.strokeColor = Reg;
    group1.filled = false;
    group1.strokeWidth = lineWidth;
    This works, but I have to this for every group and there are lots of them.
    So I tried to make a function:
    function setAttributes(temp)
    temp.stroked=true;
    temp.strokeColor = Reg;
    temp.filled = false;
    temp.strokeWidth = lineWidth;
    And then call that function for each group:
    setAttributes(group1);
    setAttributes(group2);
    setAttributes(group3);
    etc.
    Of course, this doesn't work since I have incredible programming skills
    Please help.
    Thanks!

    The script as it is should ONLY change the path items that are in your 'first level' of group items… If you need to change the properties of path items outside of the groups then you could add another loop… Heres one way you add the extra loop:
    var docRef = app.activeDocument;
    // Set variable to your color
    var reg = docRef.swatches.getByName("[Registration]");
    // Set a variable to the document path items collection
    var pathList = docRef.pathItems;
    // Loop through this list of objects
    for (var h = 0; h < pathList.length; h++)     {
         // Change the property values
         pathList[h].filled = false;
         pathList[h].stroked = true;
         pathList[h].strokeColor = reg.color;
         pathList[h].strokeWidth = 2;
    // Set a variable to the document groups collection
    var groupList = docRef.groupItems;
    // Loop through this list of objects
    for (var i = 0; i < groupList.length; i++)     {
         // Re-use variable for the groups path items collection
         pathList = groupList[i].pathItems;
         // Loop through this list of objects
         for (var j = 0; j < pathList.length; j++)     {
              // Change the property values
              pathList[j].filled = false;
              pathList[j].stroked = true;
              pathList[j].strokeColor = reg.color;
              pathList[j].strokeWidth = 2;
    app.redraw();

  • Need Help on WRFMGROUP - Manage Maintenance Groups for articles

    Hi,
    Has anybody used WRFMGROUP-Manage Maintenance Groups for articles for seasonal procuremen article creation.
    I need this to update some article master fields ( like Listing procedure) while creating the article in the background.( WRFAPC11)
    Kindly help.
    Jajati

    Hi Jajati,
    you can use the Maitenance Group to define the fields you have to maintain. Therefore, create a maintenance group in transaction WRFMGROUP. Add the needed Field Groups to the maintenance group - the field group contains the article master fields you can fill when using this maintenance group.
    As far as I know, you can use the maintenance group in transaction WRFMATBODY after releasing the article in transaction WRFAPC11. I'm not sure, if you can use the maintenance group in the releasing process. In transaction WRFMATBODY, you can the fill in all the fields assigned to the field group.
    Hope it helps.
    Regards,
    Tobias

  • How to set the Default Dashboard for a Group

    Hello,
    we have, in our project, two groups defined in the dashboard; How can we set the Default Dashboard for each Group?
    Actually every user of both groups at logon views the "my dashboard" page.
    Thank you

    hi
    check this http://obiee101.blogspot.com/2008/06/obiee-directing-user-to-default.html
    also this..
    http://bvellinger.blogspot.com/2008/04/default-dashboard-obiee.html

  • TimesTen Error :5126: A system managed cache group cannot contain non-stand

    I have created few cache groups in TimesTen.
    And when i fired script to create fillowing cache group its gives me error.
    please see the details mentioned below.
    CREATE USERMANAGED CACHE GROUP C_TBLSSTPACCOUNTINGSUMMARY
    AUTOREFRESH MODE INCREMENTAL INTERVAL 5 SECONDS STATE ON
    FROM
    schema.tablename
    ACCOUNTINGSUMMARYID DOUBLE,
    INPUTFILENAME VARCHAR(255) NOT NULL,
    ACCOUNTINGSTATUS VARCHAR(255) NOT NULL,
    RECORDCOUNT DOUBLE,
    LASTUPDATEDDATE DATE NOT NULL,
    CREATEDATE TIMESTAMP DEFAULT SYSDATE,
    PRIMARY KEY (ACCOUNTINGSUMMARYID),
    PROPAGATE);
    then error occurs like==>
    5121: Non-standard type mapping for column JISPRATCORBILLINGDEV501.TBLSSTPACCOUNTINGSUMMARY.ACCOUNTINGSUMMARYID, cache operations are restricted
    5126: A system managed cache group cannot contain non-standard column type mapping
    The command failed.

    If you have access to Oracle Metalink, Please take a look at the Note:367431.1
    Regards,
    Sabdar Syed.

  • Setting up Service desk Management

    Hi,
    We have EP 6.0 SP14. We want to set up Service Desk Management with  solution Manager.
    Could any one guide the set up steps.
    Thanks in advance
    Pradnya

    Hi Pradnya,
    Here you go as a first step to start
    http://help.sap.com/saphelp_nw04/helpdata/en/33/c7f5414e2fc517e10000000a155106/frameset.htm
    Cheers!!
    ::Do not forget to reward points if it helps.

  • Does idm support maintenance of access manager's group/role/filtered role

    The xml of Access Manager Realm Resource Adapter has object types group, role and filtered role with object feature list,create, update and delete. Does that mean with the adapter installed, we can make use the idm to maintain the access manager's group/role/filteredrole? Is there any customization/configuration needed in order to provision these features in idm?
    Thanks,

    1. The AM agent can return ldap attributes after authentication. What you can do is use Sun Directory Server Proxy to provide a virtual view of both LDAP and your DB to AM.
    2. Sun Role Manager is a tool for role mining and attestation, ie it helps with compliancy verifications which is required by many businesses these days. Sun Identity Manager does not need Sun Role Manager if you just want to provision roles for your users, however, as it appears to be the case in your envirionment, the roles created by IDM are exported to SRM for compliance verifications.

Maybe you are looking for

  • How do I use existing TM backup with upgraded Airport Extreme?

    I replaced my old Airport Extreme with a dual-band Airport Extreme. I was previously using an external drive connected to the old AE for Time Machine backups. I now have everything set up, I can see the drive on the new AE in the Finder and select it

  • Open a .pdf!!!

    Hy, I've got a file: usa-grants-inc.pdf from a friend of mine and I really need to open it. I'm trying to do that with Acrobat Reader but I keep getting an error message. Is there any other way I can open my file? I really need that information. Can

  • Java Server Faces

    Hello All, I make an application for online examination system.I face some problem with logout.When we login as a Admin then there is a 1 connection.When we see the candidate report and before coming the report if i logout in between and again we log

  • Changing the content in an IDOC segment at runtime with EXIT_SAPLF050_006

    I am using IDOC FIDCC2 type. I have to change some values of the segment E1FISEG. In EXIT: EXIT_SAPLF050_006, I am making these changes, but after the execution. When the IDOC is generated, I noticed that the value of this field is not updated in the

  • When I move items to the trash I get asked for my password.

    When I try to move any item into the trash I a screen pops up and says that the finder needs my password in order to complete this action. So once I enter in my password the item gets deleted from the desktop or wherever but does not even show up in