Hello

Hello,

I have an application that pulls some data from a service provider in JSON format.
The application makes several calls to the service provider; some calls are answered immediately but for some calls it may take a few minutes.
At the moment the application is processing the calls sequentially (single thread) but I want to improve the performance by processing the calls in multi thread mode.

As far as I can understand I have to submit a thread for each call, every thread will send the data request to the service provider independently and once received the answer will use the information to do all the actions that my application requires.
The threads will be independent from each other, I mean, I don't need one particular thread to finish before another.

This is the first time I work with multi threading and I was looking into the material available on the Internet but there are two things which are not clear to me yet.
Do I need to manage the "list of threads" that are running at the same time or do they free up when finished automatically ?
Can the same thread descendant class be created in multiple instances with the same variable ?

Many thanks

Comments

  1. Variables created in your thread class aren't sharable with other instances of the class. You can safetly run the threads.

    ReplyDelete
  2. I looked into the tasks and they seems easier to handle. I was wondering when I should use them instead of the threads.

    ReplyDelete
  3. General really really rough guideline: Use threads for long-running ongoing work. Use tasks for discrete, small items you want to occur in the background.

    Tasks can check if they're canceled so you can start them and cancel if you need to. The main issue here might be that some of your network items take minutes to complete, which sounds like something else is wrong that might need to be fixed first.

    ReplyDelete

Post a Comment