Object obj = new Object ();
Result result = new Result ();
ContactTread contactTread = new ContactTread (this, obj, result);
contactTread.start ();
synchronized (obj) {
try {
wait ();
} catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
ContactTread.java which is so
private ContentResolver cr;
private List
private Object obj;
private Result result;
public ContactTread (Context context, Object obj, Result result)
{
this.cr = context.getContentResolver ();
UserHelper userHelper = new UserHelper (context);
userList = userHelper.getUsers ();
this.obj = obj;
this.result = result;
}
@ Override
public void run ()
{
result.Value = writePhone ();
synchronized (obj) {
notify ();
}
notify ();
}
But when debugging the following statement always found an error, the error content is object not locked by thread before wait (), how does that matter
synchronized (obj) {
try {
wait ();
} catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
------ Solution ----------------------------------- ---------
I'll guess you want to achieve the following functions :
run to the activity in the main thread , open another thread A, first wait for the main thread , the thread A complete its task and then wake up the main thread
Is that so?
------ Solution ---------------------------------------- ----
object not locked by thread before wait ()
wait object gets its first lock, the lock and wait for you to take is not the same object
------ For reference only ------------- --------------------------
solve ah , do not know how a situation can not figure out where the wrong
--- --- For reference only ---------------------------------------
Yes , is the meaning
没有评论:
发表评论