java - Android mediator pattern with threads -
i got next problem:
i want utilize mediator pattern app.
i got producer creates values. got mediator stores values in queue(which private, getters , setters exist) , notifices consumer there new values in queue. got consumer, gets notified new value, gets , stuff it...
i want 3 classes run on own threads. want efficient.
if understand right, mediator thread gced when run() ends... need maintain live loop, don't i? while(true), not efficient. there improve way? or totally wrong , mediator wouldn't gced?
thanks in advance
you're right 1 time mediator object's run()
method returns, thread terminate. doesn't mean mediator gced; if there live reference mediator object, won't be. however, if thread has exited, mediator won't particularly useful. while(true)
loop 1 way deal this. while(true)
loop not inefficient. work calling wait()
on object until new stuff appears in queue. thread in wait state , not consume cpu resources.
java android multithreading mediator
No comments:
Post a Comment