![good morning in bengali good morning in bengali](https://i.pinimg.com/736x/83/b2/f7/83b2f7e3b26c6f6c51a30958ac7d9b03.jpg)
If the next thread comes, it must wait until the execution of the previous thread to attain the class level lock.
![good morning in bengali good morning in bengali](https://1.bp.blogspot.com/-t-nVDUUhD8o/XiLj8L4jNbI/AAAAAAAAMEg/uGjZhWcO2YQL10t9k5XGFqOnPNgKGlKyACLcBGAsYHQ/s1600/good%2Bmorning%2Bimages%2Bwith%2Bbengali%2Bquotes%2B%2817%29.jpg)
The child threads start their execution t1, and as the wish method is static synchronized, the thread t1 gains the class level lock of class Display and starts executing the wish method. First, we create two child threads and assign them to the display objects for the threads, and after t2.start(), there will be three threads, namely(main,t1,t2), and the execution procedure is as follows.
#Good morning in bengali code#
class Display: The code which needs for the child thread to run.In the above program, three classes, namely Display, MyThread, and Main, are defined where each class has – t 6.method5() starts execution as it is an instance method or a normal methodĮxample: Below is an example program of multithreading with static synchronized.t5.method4() starts execution as it is instance or(normal) level synchronized method and requires object level lock, so it attains object level lock.t4.method3() starts execution as it is static methods requires no lock.t3.method2() waits as it requires class level lock, so it must wait until t1 releases the lock.t2.method2() wait for its time to start execution, as it is a static synchronized method, it requires a class level lock, as t1 has already acquired class level lock t2 must wait until t1 execution.t1.method1() starts execution as it attains class level lock of Manager class.Method4: public synchronized int method4() Method2: public static synchronized void method2() Method1: public static synchronized void method1() Here t1,t2… t6 are the thread names The complete declarations of methods are: Note: When a class has both synchronized and static synchronized methods they can run parallelly ,as those two methods require different locks. Syntax: synchronized static return type class name The Thread will acquire a class level lock of a java class, such that only one thread can act on the static synchronized method. We are attaining a class-level lock such that only one thread will operate on the method. The only difference is by using Static Synchronized. Static Synchronized method is also a method of synchronizing a method in java such that no two threads can act simultaneously static upon the synchronized method. To maintain the Synchronized behavior, we need a class-level lock rather than an instance-level lock which can be achieved by Static Synchronization. When there are more objects of a class, It acquires only the lock of the particular instance. The Synchronized method may lose its behavior of getting an ordered output. Use synchronized keywords when it is required and try to use synchronized block.Synchronization is the most dangerous word in java because this is the only reason for the deadlock.If a method or block is synchronized, then it requires an object-level lock to start execution.It is only for methods that are at the Object level.To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. ISRO CS Syllabus for Scientist/Engineer ExamĪttention reader! Don’t stop learning now.ISRO CS Original Papers and Official Keys.GATE CS Original Papers and Official Keys.