Skip to content

Commit

Permalink
[JENKINS-32622] Switch to a ThreadLocal DateFormatter
Browse files Browse the repository at this point in the history
Attempt to avoid a deadlock observed in remoting by not causing any remote
classes to be loaded when we are logging.
  • Loading branch information
jtnord committed Jan 26, 2016
1 parent 751b73f commit bf508eb
Showing 1 changed file with 10 additions and 5 deletions.
Expand Up @@ -24,11 +24,9 @@

package com.cloudbees.jenkins.support;

import org.apache.commons.lang.time.FastDateFormat;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
Expand All @@ -39,7 +37,14 @@
* @author Stephen Connolly
*/
public class SupportLogFormatter extends Formatter {
FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ");

private final static ThreadLocal<SimpleDateFormat> threadLocalDateFormat = new ThreadLocal() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
}
};

private final Object[] args = new Object[6];

@Override
Expand All @@ -49,7 +54,7 @@ public class SupportLogFormatter extends Formatter {
)
public String format(LogRecord record) {
StringBuilder builder = new StringBuilder();
builder.append(fdf.format(new Date(record.getMillis())));
builder.append(threadLocalDateFormat.get().format(new Date(record.getMillis())));
builder.append(" [id=").append(record.getThreadID()).append("]");

builder.append("\t").append(record.getLevel().getName()).append("\t");
Expand Down

0 comments on commit bf508eb

Please sign in to comment.