-
Notifications
You must be signed in to change notification settings - Fork 26.4k
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
Simple date format each time new object creation removed #3027
Changes from 1 commit
7956c15
fae5fa8
3e6ae66
5607b0a
5d3398b
89e5485
1288f12
98adaac
59188bc
f53137d
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 |
---|---|---|
|
@@ -75,6 +75,20 @@ public class AccessLogFilter implements Filter { | |
|
||
private static final long LOG_OUTPUT_INTERVAL = 5000; | ||
|
||
static ThreadLocal<SimpleDateFormat> FILE_DATE_FORMATTER= new ThreadLocal<SimpleDateFormat>() { | ||
@Override | ||
protected SimpleDateFormat initialValue() { | ||
return new SimpleDateFormat(FILE_DATE_FORMAT); | ||
} | ||
}; | ||
|
||
static ThreadLocal<SimpleDateFormat> MESSAGE_DATE_FORMATTER= new ThreadLocal<SimpleDateFormat>() { | ||
@Override | ||
protected SimpleDateFormat initialValue() { | ||
return new SimpleDateFormat(MESSAGE_DATE_FORMAT); | ||
} | ||
}; | ||
|
||
private final ConcurrentMap<String, Set<String>> logQueue = new ConcurrentHashMap<String, Set<String>>(); | ||
|
||
private final ScheduledExecutorService logScheduled = Executors.newScheduledThreadPool(2, new NamedThreadFactory("Dubbo-Access-Log", true)); | ||
|
@@ -113,7 +127,7 @@ public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException { | |
String version = invoker.getUrl().getParameter(Constants.VERSION_KEY); | ||
String group = invoker.getUrl().getParameter(Constants.GROUP_KEY); | ||
StringBuilder sn = new StringBuilder(); | ||
sn.append("[").append(new SimpleDateFormat(MESSAGE_DATE_FORMAT).format(new Date())).append("] ").append(context.getRemoteHost()).append(":").append(context.getRemotePort()) | ||
sn.append("[").append(MESSAGE_DATE_FORMATTER.get().format(new Date())).append("] ").append(context.getRemoteHost()).append(":").append(context.getRemotePort()) | ||
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. Another thing we should consider is that when we clear the threadlocal's value. 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. @carryxyh 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. @carryxyh would you suggest is there any things I needs to change here? |
||
.append(" -> ").append(context.getLocalHost()).append(":").append(context.getLocalPort()) | ||
.append(" - "); | ||
if (null != group && group.length() > 0) { | ||
|
@@ -174,8 +188,8 @@ public void run() { | |
logger.debug("Append log to " + accesslog); | ||
} | ||
if (file.exists()) { | ||
String now = new SimpleDateFormat(FILE_DATE_FORMAT).format(new Date()); | ||
String last = new SimpleDateFormat(FILE_DATE_FORMAT).format(new Date(file.lastModified())); | ||
String now = FILE_DATE_FORMATTER.get().format(new Date()); | ||
String last = FILE_DATE_FORMATTER.get().format(new Date(file.lastModified())); | ||
if (!now.equals(last)) { | ||
File archive = new File(file.getAbsolutePath() + "." + last); | ||
file.renameTo(archive); | ||
|
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.
Hi, khan
We have integrated Netty's FastThreadLocal in dubbo. I think we can use it instead of ThreadLocal. I suggest you refer to RpcContext.LOCAL.
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.
Thanks for suggesting this. I was looking into RpcContext code for LOCAL and SERVER_LOCAL implementation, I would like to go this approach.
I am very curious to know, the difference between LOCAL and SERVER_LOCAL here. Is LOCAL is used for when the call is from consumer and SERVER_LOCAL is used for,when call is served by SERVER? Is this understanding of mine is correct?