• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two theads running concurr. using the same method

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I'm sending SMS through two phones connected to my PC.
So I have a CService class for each.
On a button click I want to create two threads so that the constructor
takes a CService object as a parameter and starts sending messages.
But each of these theads have to run concurrently and use a method getClientName().
Client Names I store in a Vector. Event if I create two mehtods
getClientName_1() and getClientName_2() they will anyway access the same Vector.
How can I do so that the threads run concurrently and do not conflict with each other using the
getClientName() method?
Thatnk you!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you just read from the Vector, two threads accessing it at the same time won't be a problem at all.
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My code will look like this

class SMSSender extends Thread{
SMSSender(CService service){
public void run(){
for(int i=0; i<MyVector.size(); i++)
String clName = getClientName(i); //These are
String clSurname = getClientSurname(i); // read from the Vector
createSMS();
sendSMS();
}
}
}

//on a button click

SMSSender sender1 = new SMSSender(service1);
SMSSender sender2 = new SMSSender(service2);
sender1.start();
sender2.start();
}

Will there be any conflict in this case?
if that doesn trouble you please give explanation!
Thank you!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic