0

I have 3 classes

  • View Class
  • Request Class
  • Response Class

Ia calling two methods in my request class from my view class like so;

[eRequests GetM:IdString];
[eRequests GetY:IdString SubID:subIdString];

My thread starts to execute the first line and gets halfway though its process then the next request starts before the first has even come back.

I would like to prevent this from happening however I am not really sure how to proceed.

The thing thats stopping me is that a request like this will go through these steps

  1. Call request method - inside ViewClass
  2. Create packet and send request receive the data returned from the db - inside Requestclass
  3. Send data to ResponseClass - inside Requestclass
  4. decode data and send relevant information back to receiver method in ViewClass - inside Response Class

The thing I'm abit stuck on is when the thread comes back to the viewclass but inside the different method how do I get back to the second request?

Anyway if anyone can provide some help on allowing me to execute one method call at a time that would be hugely appreciated!

1 Answer 1

0

Your description is highly confusing. What is the "my thread" which is executing the posted code? Is it the request thread or the response thread? Why do you need to "get back to the second request"? The steps 1-4 are trying to explain that it's the Response object which is calling back to View, and then in the next sentence talking again about Request? So which thread is it?

From the words you are using i am just guessing that you have simple race condition going on, which means that eRequest is a shared resource and as a such needs to be mutexed

@synchronized(eRequests) {
 [eRequests GetM:IdString];
 [eRequests GetY:IdString SubID:subIdString];
}

But i still don't understand the "getting back to the second request" part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.