java - What synchronization method should I use for pausing a consumer queue thread? -
i have android application linkedblockingqueue i'm using run series of network jobs on separate thread (call network thread). when response network job need pause jobs user input dialog. i'd block network thread until user input complete, , unblock can continue process network jobs. concurrency mechanism makes sense here?
edit: since pausing performed based on results of network job, pausing event comes network thread,
edit: edit makes resolution bit easier. still need signaling can scratch complicated mess put in. can use simple reentrantlock , flag.
maybe this
boolean needstowaitforuserinput = false; final reentrantlock lock = new reentrantlock(); final condition waitingcondition = lock.newcondition(); private final runnable networkrunnable=new runnable(){ public void run(){ //get network information lock.lock(); needstowaitforuserinput = true; try{ while(needstowaitforuserinput ){ waitingcondition.await(); } }finally{ lock.unlock(); } } } public void signaljobtocontinue(){ lock.lock(); try{ needstowaitforuserinput =false; waitingcondition.signal(); }finally{ lock.unlock(); } }
Comments
Post a Comment