This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Handling a lengthy operation

Apr 20th, 2009, 03:07 AM

Hey,
One of our application tasks is sending bulk SMS.
The application is built with Hibernate/Spring/Wicket
The user chooses which groups to be sent to and then submit the form via Ajax.
The flow is as the following:
- Sending the SMS to each contact in the group.
- Save the SMS to the DB.
- Update the group status.
- Handle the next group.
Sending the SMS could be a lengthy operation so I'm thinking to create a multiple thread (say each thread handle 100 contact), but I'm not sure if this will has an impact on the DB transaction.
How do you advice me to implement this functionality? do suggest any technique?
Are threads necessary?
Thanks.

There are a lot of ways to implement the sending functionality. You could use a database to persist the state and make sharing state between clusters possible, but this smells like volatile data and databases aren't well suited for that. So perhaps some kind of distributed heap would be better (Terracotta, Gigaspaces, Tangosol). Just store all messages that need to be send in the heap (that is visible on all machines) and let threads from each machine process messages in parallel.

But more information about your requirements and constraints are needed