📄 synchblock.java
字号:
public class SynchBlock implements Runnable
{
static int myArray[];
public void run()
{
try
{
Thread.sleep(500);
System.out.println("new thread just woke up");
synchronized(myArray)
{
for(int i=0; i < myArray.length; i++)
System.out.println("inside run i="+i+" loation = " + myArray[i]);
}
}catch(InterruptedException e){}
}
public static void main(String args[]) throws InterruptedException
{
myArray = new int[3];
Thread t = new Thread(new TrivialApplication() +"");
t.start();
synchronized(myArray)
{
Thread.sleep(2000);
System.out.println("inside synch block");
myArray[0] = 30;
myArray[1] = 20;
myArray[2] = 10;
Thread.sleep(2000);
System.out.println("about to leave synch block");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -