multithreading - Java synchronization with callback -
i developing module inside system based on event user has receive sms.
i have following situation
synchronized(notificationphonenumber) { smsprovider.sendsms(notificationphonenumber, smstext); } the code of method sendsms running asynchronious:
public static void send(final notificationphonenumber npn, final string smstext) { thread smssender = new thread(new runnable() { public void run() { //sms sending code runs here.... } }); smssender.start(); } so question how long notificationphonenumber object locked in case? going locked time thread finishes job or not?
as long
smsprovider.sendsms(notificationphonenumber, smstext); doesn't return. means, sendsms() method create thread , return. amount of time.
also, if start thread in method. created thread hold reference not lock after sendsms() returns.
the lock , synchronization external sendsms(). whichever thread calls sendsms() acquire lock , code within sendsms() has no knowledge of it.
Comments
Post a Comment