zoukankan      html  css  js  c++  java
  • java SimpleDateFormat非线程安全测试

    public class MyThread extends Thread {
    private SimpleDateFormat sdf;
    private String dateString;
    
    public MyThread(SimpleDateFormat sdf ,String dateString){
    super();
    this.sdf = sdf;
    this.dateString = dateString;
    }
    
    public void run(){
    try {
    Date dateRef = sdf.parse(dateString);
    String newDateString = sdf.format(dateRef).toString();
    if(!newDateString.equals(dateString)){
    System.out.println("ThreadName = " + this.getName()
    +" 报错了 日期字符串: "+ dateString+" 转换成的日期为: "+ newDateString);
    }
    } catch (ParseException e) {
    e.printStackTrace();
    }
    }
    }
    

      

    public class Test {
    
    public static void main(String[] args) {
    
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String[] dateStringArray = new String[]{"2000-01-02","2000-02-01","2000-03-01","2000-04-01","2000-05-01",
    "2000-06-01","2000-07-01","2000-08-01","2000-09-01","2000-10-01"};
    MyThread[] threadArray = new MyThread[10];
    for(int i = 0; i < 10; i++){
    threadArray[i] = new MyThread(sdf,dateStringArray[i]);
    }
    for(int i = 0 ; i < 10; i++){
    threadArray[i].start();
    }
    }
    
    }
    

      

  • 相关阅读:
    7. Reverse Integer
    2. Add Two Numbers
    1039. 顺序存储二叉树
    Codeforces 535D
    Codeforces 385D
    URAL
    URAL
    Codeforces Round #428 (Div. 2)
    鹰蛋坚硬度实验
    Codeforces Round #392 (Div. 2)-D. Ability To Convert
  • 原文地址:https://www.cnblogs.com/sheikh/p/5722396.html
Copyright © 2011-2022 走看看