多线程并发情况下使用日期转换函数

最近,要对每条log进行日期过滤,由于log日期是这种样式的“2018-08-03 00:00:00”,需要在过滤的时候将其转化成long类型进行比较筛选,这时候就要用到SimpleDateFormat了,但是,由于rdd有多个分区,各个分区并行执行,考虑到线程安全和资源问题,最后使用了第三方jar包的FastDateFormat

  val dateFormat = FastDateFormat.getInstance("yyyy年MM月dd日,E,HH:mm:ss")

  def filterByTime(fields: Array[String], startTime: Long, endTime: Long): Boolean = {
    val time = fields(1)
    val logTime = dateFormat.parse(time).getTime
    logTime >= startTime && logTime < endTime
  }
 

猜你喜欢

转载自blog.csdn.net/weixin_41228362/article/details/83216482