Hi All, Thanks for the responses.
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:32 PM, Danushka Fernando <[email protected]>wrote: > Hi > Check my in line comments. > > On Apr 21, 2014 7:36 AM, "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? > AFAIU no need to. To make sure you can write some sample with few prints > in static method. Put some sleeps in between. Then it will make it easy to > test. Then run several threads. > > > > > 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 > > > >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
