0

I have an Android App and a Server for maintenance. My App has a onetime registration process, where the user has to add a unique ID. And for this unique ID the user gets his data from the server. And the server gets this data from another Webservice.

App -> data request to App server -> request to other webservice -> repsonse from webservice to app server -> response from App server to App

Now this works for only ONE user, but now it has to work for more user or respectively for a endless amount of users. And I dont know exactly how to do this well.

Does it work with multithreading? That I create for each user a own thread? or how do I handle this that this works parallel and each user gets his data when he wants.

Can anyone give me some help?

  • Are you trying to multi-thread Android here or is the server running Android? How does Android come into the solution you are considering? – Peter Lawrey Apr 28 '14 at 07:56
  • I have a Android App and this App is only working with a java server, from where the user gets the data. –  Apr 28 '14 at 07:57
  • So the solution you need to write could be talking to anything. – Peter Lawrey Apr 28 '14 at 07:58
  • I dont understand. what you mean? –  Apr 28 '14 at 07:58
  • You tagged `[Android]` but the solution doesn't really have anything to do with Android. You shouldn't be thinking about the server being Android specific. – Peter Lawrey Apr 28 '14 at 08:02
  • 1
    An endless amount of users? Are you working for Google? The real question is how many concurrent users are you going to have per second? And please, don't tell us "an endless amount". How long is a typical session? How many sessions can your server handle at once? Also, what kind of data is that? Can some of that data be cached (either on the intermediary server or on the device itself)? or shared across multiple users? – Stephan Branczyk Apr 28 '14 at 08:07

2 Answers2

1

Its server side problem, its nothing to do with android. For this make sure that your sever code capable to handle multiple request at a time.

KUR
  • 11
  • 3
  • yes, but I want to know how to handle this multiple requests? so that my app works for a endless amount of users and each user gets his own data when he wants. –  Apr 28 '14 at 08:02
  • normally all the request process sequentially on server so if you request multiple time on server or multiple request from multiple users,all those request execute sequentially,if you want it parallel then you have to work on processor level – KUR Apr 28 '14 at 08:11
  • yes ok than it should work sequentially. Do I have to make it multithreading, is it? –  Apr 28 '14 at 08:23
0

I suggest you look at netty. It is designed for flexibility and scalability and even if your write your own, you should understand how it works.

It can handle tens of thousands of connections and is a good start to writing a multi-threaded application efficiently.

In terms of how to write a multi-threaded application I suggest you read Java Concurrency in Practice. If you only read one Java book this year, make sure you have read this one.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • yes is looks good. But I my function of my app is finished theoretically, but it only works for one user. But now it should work for an endless amount of users, and my quesetion was how to handle more users that work parallel. –  Apr 28 '14 at 08:04
  • @aut_silvia You are going to have to start again because you will have undoubtedly made assumptions which are not valid for multiple users. If have say ten years experience writing multi-threaded applications, you might not need to write it again, but if you don't have so much experience I can suggest that trying to change an existing program incrementally is *much* harder than just writing it again. – Peter Lawrey Apr 28 '14 at 08:07
  • @aut_silvia Consider this example, you have a coffee shop and you have learnt how to make coffee for one person at a time, you now want to know how to make a thousand coffees at once for people all over the world. That is a completely different business. Understanding how to write multi-threaded programs is perhaps the thing developers with 5-10 years commercial experience find the most challenging, don't underestimate how hard it is. – Peter Lawrey Apr 28 '14 at 08:10
  • ok you are maybe right. But my question was about it, how to make it the best way to handle multiple users and requests. But what I can found out of your answer is to do this with multithreading, is it? –  Apr 28 '14 at 08:12
  • The answer is no. Multi-threading shouldn't be the first thing you look at to scale your server instance (often times, multi-threading will be used as part of a larger solution that deals with your problem, but starting with researching multi-threading is the wrong approach if you're just beginning to tackle this issue). – Stephan Branczyk Apr 28 '14 at 08:28
  • @StephanBranczyk What do you suggest instead? (Apart from understanding the problem better) – Peter Lawrey Apr 28 '14 at 08:41
  • @aut_silvia I would start with a solution which helps you write scalable services such as netty. As you do this, using multiple threads is likely to become unavoidable. esp if you want database access as well as this is typically synchronous. – Peter Lawrey Apr 28 '14 at 08:42
  • Tell us more about the application you want to write. Tell us your idea. Tell us your level as a developer, and what if any other applications you've written whether they were school projects, or toy projects you've never finished. Then, we may be able to suggest an adequate starting point. Depending on your requirements, there may existing solutions we can suggest that you can use as shortcuts for parts of your application. – Stephan Branczyk Apr 28 '14 at 19:28