0

I am programming a sms desktop app with java using smslib, my program needs to store sms in a database table, then compare the sms with another table, and finally return a new sms, how to implement this process, with threads?? timers? I need to keep the app running all the day, the program just need to compare numbers with another table and then return the ones that are different, I have the app but in parts, I just want to know your approach, the user needs to receive a sms with the new numbers thanks

p.d I use smslib and the classes readmessages and sendmessages. I am stucked in this part, I dont want that my program crashes

AlexR
  • 114,158
  • 16
  • 130
  • 208
bentham
  • 1,701
  • 3
  • 20
  • 32

1 Answers1

1

SMSLib has 2 ways to receive messages.

  • using Service.readMessages(). This requires implementing some kind of scheduling. For example your own thread or timer task.
  • implementing callback. This is IMHO preferable way. In this case the library cares about scheduling and everything. You just implement the callback that will be called by SMSLib when SMS message arrives. I just have to store it in DB and implement the logic you described that compares messages and sends replies.

Due to sending messages may take some time (sometimes several seconds) you should do this asynchronously. Moreover the sending might fail, so you probably will have to implement retry mechanism. So, use queueing. The simplest way is to use Executors framework from java.concurrency package.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • where can I see the callback in smslib?, do you have an example of app queueing? why executor framework?? – bentham May 01 '12 at 14:23