-
Notifications
You must be signed in to change notification settings - Fork 782
[Scheduler] Dropped usage of SimpleDateFormat for trace logging #3508
Conversation
@@ -38,8 +37,6 @@ | |||
|
|||
private final static Logger logger = LoggerFactory.getLogger(ExpressionThreadPoolManager.class); |
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.
I know its not part of the PR but maybe you can change the logger to privat final
right away.
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.
I feared this would catch sb's eye 😉
No, it's not that easy, but will do so.
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.
Then let's do it in another PR as this change is not related at all. Okay?
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.
Thank you for that changes.
Perhaps you can also add the change for the comment of @htreu
done |
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.
@SJKA I found a few other things on review.
The question about the class used for the logger is really affected by changes of this PR.
Some other comments has been added because I found on while looking at the code.
@@ -86,7 +84,8 @@ public ExpressionThreadPoolExecutor(final String poolName, int corePoolSize) { | |||
@Override | |||
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor) { | |||
// Log and discard | |||
logger.warn("Thread pool '{}' rejected execution of {}", | |||
LoggerFactory.getLogger(ExpressionThreadPoolExecutor.class).warn( |
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.
As we create here a implementation of the ThreadPoolExecutor.DiscardPolicy class, shouldn't we add a logger to that implementation using the class it implements?
@@ -86,7 +84,8 @@ public ExpressionThreadPoolExecutor(final String poolName, int corePoolSize) { | |||
@Override | |||
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor) { | |||
// Log and discard | |||
logger.warn("Thread pool '{}' rejected execution of {}", | |||
LoggerFactory.getLogger(ExpressionThreadPoolExecutor.class).warn( | |||
"Thread pool '{}' rejected execution of {}", | |||
new Object[] { poolName, runnable.getClass() }); |
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.
Not introduced by your changes, but do we need to create an array of the two logger arguments?
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.
done - plus I reduced the severity to DEBUG as the comment suggests this actually is expected to happen during shutdown.
@@ -59,7 +54,8 @@ static public ExpressionThreadPoolExecutor getExpressionScheduledPool(String poo | |||
((ThreadPoolExecutor) pool).setKeepAliveTime(THREAD_TIMEOUT, TimeUnit.SECONDS); | |||
((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true); | |||
pools.put(poolName, pool); | |||
logger.debug("Created an expression-drive scheduled thread pool '{}' of size {}", | |||
LoggerFactory.getLogger(ExpressionThreadPoolManager.class).debug( |
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.
Also not really part of this PR: If and only if you do another change again, WDYT about changing static public
to public static
to get the common keyword order?
@@ -59,7 +54,8 @@ static public ExpressionThreadPoolExecutor getExpressionScheduledPool(String poo | |||
((ThreadPoolExecutor) pool).setKeepAliveTime(THREAD_TIMEOUT, TimeUnit.SECONDS); | |||
((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true); | |||
pools.put(poolName, pool); | |||
logger.debug("Created an expression-drive scheduled thread pool '{}' of size {}", | |||
LoggerFactory.getLogger(ExpressionThreadPoolManager.class).debug( | |||
"Created an expression-drive scheduled thread pool '{}' of size {}", | |||
new Object[] { poolName, cfg }); |
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.
Also not really part of this PR: Why using an array for the arguments?
...as it slows down the scheduler and was used in a dangeriously wrt thread-safety. fixes eclipse-archived#3505 fixes eclipse-archived#3506 Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
@@ -36,18 +35,14 @@ | |||
*/ | |||
public class ExpressionThreadPoolManager extends ThreadPoolManager { | |||
|
|||
private final static Logger logger = LoggerFactory.getLogger(ExpressionThreadPoolManager.class); |
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.
Instead of using logger for every inner class, you could also do this:
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
This will be automatically resolved for every class instance that uses it.
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.
Are you really sure that this will give a different logger class when calling the same instance from the different locations, I cannot see how that would work out. The lookup is done only once when initializing.
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.
I actually use this in inheritance pattern in which the logger is mentioned in interface or base (abstract) class so that the logger gets resolved for every child class instances. I completely overlooked in this scenario that it will be resolved only for the top-level class during instantiation and the same logger instance will be used by the inner classes.
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.
:-)
* master: (335 commits) Voice: send feedback to an item when listening for a command (eclipse-archived#3451) Scheduler: fix ConcurrentModificationException (eclipse-archived#3511) [Scheduler] Dropped usage of SimpleDateFormat for trace logging (eclipse-archived#3508) Use % sign as default for dimmer items (eclipse-archived#3525) updated ThingHandler javadoc added regression tests ensure thingUdpated cannot be called in parallel with initialize moving handler intiialization back to the caller thread use decicated locks instead of syncrhonization by object add PaperUI setup to IDE setup tasks, adopt documentation (eclipse-archived#3515) Bug fix: things not showing on control page (eclipse-archived#3517) remove "Type" postfix in item events, fixes 3282. (eclipse-archived#3494) use toFullString when creating GroupItemStateChangeEvent (eclipse-archived#3409) Made item’s state text consistent + refactored code (eclipse-archived#3466) Refactored CoreItemFactory: (eclipse-archived#3507) Add CoreItemFactoryTest, in addition to eclipse-archived#3507 (eclipse-archived#3509) fix ConcurrentModificationException in AbstractWatchServiceTest (eclipse-archived#3499) BasicUI: Treat Switch on NumberItem not as ON/OFF Switch (eclipse-archived#3493) An Interface method should not allow for throwing a generic Exception (eclipse-archived#3467) Fix eclipse-archived#2902 for Basic UI (eclipse-archived#3496) ... # Conflicts: # bundles/io/org.eclipse.smarthome.io.transport.dbus/.classpath # bundles/io/org.eclipse.smarthome.io.transport.dbus/META-INF/MANIFEST.MF # extensions/binding/pom.xml
...as it slows down the scheduler and was used in a dangeriously
wrt thread-safety.
fixes #3505
fixes #3506
Signed-off-by: Simon Kaufmann simon.kfm@googlemail.com