Hi Chamil, Thanks for the quick response.
Regards, Sohani Sohani Weerasinghe Software Engineer WSO2, Inc: http://wso2.com Mobile : +94 716439774 Blog :http://christinetechtips.blogspot.com/ Twitter : https://twitter.com/sohanichristine On Mon, Apr 21, 2014 at 8:21 PM, Chamil Jeewantha <[email protected]> wrote: > B.staticMethod() is already thread safe (it is synchronized). because of > that, the caller class (Class A) do not need to use a lock again. > > > On Mon, Apr 21, 2014 at 8:04 PM, Sohani Weerasinghe <[email protected]>wrote: > >> Hi All, >> >> Since synchronization on static methods is a class level locking a second >> thread can't access the method until first thread releases the lock. The >> static method has synchronized as shown below. >> >> public class B{ >> public *synchronized* static void staticMethod(String a){ >> } >> } >> >> If this method calls by another class (Class A), then do I have to use a >> synchronized block as shown below to avoid multiple threads accessing the >> static method? >> >> Public class A { >> *private static Object lock = new Object();* >> >> public static void main(String[] args){ >> *synchronized(lock){* >> B.staticMethod("hello"); >> *}* >> } >> } >> >> Can someone provide a solution on this ? >> >> Regards, >> Sohani >> >> Sohani Weerasinghe >> Software Engineer >> WSO2, Inc: http://wso2.com >> >> Mobile : +94 716439774 >> Blog :http://christinetechtips.blogspot.com/ >> Twitter : https://twitter.com/sohanichristine >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > > > -- > K.D. Chamil Jeewantha > Associate Technical Lead > WSO2, Inc.; http://wso2.com > Mobile: +94716813892 > >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
