避免以上的问题可采用对数据进行加锁的方法

避免以上的问题可采用对数据进行加锁的方法

每个对象除了属性和方法,都有一个monitor(互斥锁标记),用来将这个对象交给一个线程,只有拿到monitor的线程才能够访问这个对象。

Synchronized:这个修饰词可以用来修饰方法和代码块

 1 package TomTexts;
 2 import java.io.*;
 3 public class TomTexts_38 {
 4     public static void main(String [] args) 
 5     {
 6     try
 7     {
 8     System.out.println("…正在运行程序…");
 9     throw new IOException("用户自行产生异常");
10     }
11     catch(IOException e)
12     {
13     System.out.println("已捕获了该异常!");
14     }
15     }
16 
17 }
原文地址:https://www.cnblogs.com/borter/p/9425133.html