Skip to content
Permalink
Browse files
[JENKINS-32622] Switch to a ThreadLocal DateFormatter
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 bf508eb6535d3d907839f924062772fd9aa6cba7
Showing with 10 additions and 5 deletions.
  1. +10 −5 src/main/java/com/cloudbees/jenkins/support/SupportLogFormatter.java
@@ -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;
@@ -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
@@ -49,7 +54,7 @@
)
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");

0 comments on commit bf508eb

Please sign in to comment.