-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPARK-1278: Fix improper use of SimpleDateFormat #179
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,20 +15,23 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.deploy | ||
package org.apache.spark.ui | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
|
||
/** | ||
* Utilities used throughout the web UI. | ||
*/ | ||
private[spark] object DeployWebUI { | ||
val DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss") | ||
private[spark] object WebUI { | ||
// SimpleDateFormat is not thread-safe. Don't explore it to avoid improper use. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "expose" it? I can change this too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for correcting the typo. |
||
private val dateFormat = new ThreadLocal[SimpleDateFormat]() { | ||
override def initialValue(): SimpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss") | ||
} | ||
|
||
def formatDate(date: Date): String = DATE_FORMAT.format(date) | ||
def formatDate(date: Date): String = dateFormat.get.format(date) | ||
|
||
def formatDate(timestamp: Long): String = DATE_FORMAT.format(new Date(timestamp)) | ||
def formatDate(timestamp: Long): String = dateFormat.get.format(new Date(timestamp)) | ||
|
||
def formatDuration(milliseconds: Long): String = { | ||
val seconds = milliseconds.toDouble / 1000 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,10 @@ class FileLogger( | |
overwrite: Boolean = true) | ||
extends Logging { | ||
|
||
private val DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss") | ||
private val dateFormat = new ThreadLocal[SimpleDateFormat]() { | ||
override def initialValue(): SimpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss") | ||
} | ||
|
||
private val fileSystem = Utils.getHadoopFileSystem(new URI(logDir)) | ||
private var fileIndex = 0 | ||
|
||
|
@@ -111,7 +114,7 @@ class FileLogger( | |
def log(msg: String, withTime: Boolean = false) { | ||
val writeInfo = if (!withTime) msg else { | ||
val date = new Date(System.currentTimeMillis()) | ||
DATE_FORMAT.format(date) + ": " + msg | ||
dateFormat.get.format(date) + ": " + msg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one I don't think can be used from multiple threads. But I agree why not make it thread safe in case we ever do. |
||
} | ||
writer.foreach(_.print(writeInfo)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think you can drop the first type declaration here. Not a big deal -I'll just clean it up when merging.