Spark编程注意事项

来源:互联网 发布:淘宝和京东的采购模式 编辑:程序博客网 时间:2024/06/05 07:37

SimpleDateFormat

我们使用spark做数据处理最频繁使用的就是simpleDateFormat来转化日期格式,在实践中发现,sdf总是莫名其妙的出现错误,例如:“java.lang.NumberFormatException: For input string: “””,而且有时候出现错误的记录个数都不一样。后来通过查阅SimpleDateFormat有这么一段内容:

Date formats are not synchronized. * It is recommended to create separate format instances for each thread. * If multiple threads access a format concurrently, it must be synchronized * externally.

说明simpleDateFormat不是多线程安全的。因此我们需要使用ThreadLocal来完成线程安全。

0 0
原创粉丝点击