Thanks. In the following code, which object is synchronized?
public class TestThread implements Runnable
new Thread(this,"Test 1").start();
new Thread(this,"Test 22").start();
synchronized public void run()
System.out.println((i++)+"....Sync block 1 :"+Thread.currentThread().getName());
public static void main(String args) throws InterruptedException
During the execution of a synchronized method, the thread holds the monitor for that method's object, or if the method is static, it holds the monitor for that method's class. If another thread is executing the synchronized method, your thread is blocked until that thread releases the monitor (by either exiting the method or by calling wait()).
Sorry ramjeev, musthafa is right. "this" is the method's object.
See Java Lanmguage ref:
126.96.36.199 synchronized Methods
A synchronized method acquires a monitor (§17.1) before it executes. For a class (static) method, the monitor associated with the Class object for the method's class is used. For an instance method, the monitor associated with this (the object for which the method was invoked) is used.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...