multithreading - How to implement a multiquestion poll thread in Java for multiple users? -
i have question regarding java threading. scenario:
- 2 different people receive multiquestion poll in mobile phones.
- when questions sent, server stays in wait() status until answer received. then, notify() signal sent poll continue, until questions sent.
- user 1 answering question 3 while user 2 still answering question 1.
my approach far has been implement new chainedpollthread thread. anyway, way, if user 1 answers question 1 both users 1 , 2 receive second question.
do need create new chainedpollthread each user?
if number of users increments, mean need create, example, 100 threads?
which appropiate way implement want achieve?
thanks in advance.
the way multithreading goes you'll need 1 thread each participant.
the way implemented means 1 person answers question, whole state of server-side program advanced question two. having 1 thread (and thus, if will, 1 poll-program) each of participants aleviate problem.
to reduce server-load due unnecessary amounts of threads, use thread-pooling (see http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html). thread pool re-uses existing threads once not needed more, trying keep size of active threads minimum. (creating threads expensive part) if more needed, pool grows specified maximum, if less needed shrinks specified minimum.
on other hand, whole model has few dangers: if person doesn't answer @ all? there timeout on server? wait forever?
one option might install software / framework on mobile devices, capable of receiving questions , possible answers poll , present them 1 after other on screen. participant presses "finish" set of chosen answers sent you. way server not need hold threads each participant, receive 1 string answers.
Comments
Post a Comment