6.5线程不安全的类与写法

常见的线程不安全类与写法

  • StringBuilder→StringBuffer

    StringBuilder线程不安全

    StringBuffer线程安全

  • SimpleDateFormat→JodaTime

    SimpleDateFormat线程不安全

    JodaTime线程安全

  • ArrayList、HashSet、HashMap等Collections

    ArrayList、HashSet、HashMap线程不安全

  • 先检查再执行:if(condition(a)){handle(a);}

    不安全

请自行设计类,验证线程安全性

Last updated

Was this helpful?