Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

[Scheduler] Dropped usage of SimpleDateFormat for trace logging #3508

Merged
merged 1 commit into from
May 26, 2017

Conversation

sjsf
Copy link
Contributor

@sjsf sjsf commented May 23, 2017

...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

@@ -38,8 +37,6 @@

private final static Logger logger = LoggerFactory.getLogger(ExpressionThreadPoolManager.class);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

@maggu2810 maggu2810 left a 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

@sjsf
Copy link
Contributor Author

sjsf commented May 23, 2017

done

Copy link
Contributor

@maggu2810 maggu2810 left a 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(
Copy link
Contributor

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() });
Copy link
Contributor

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?

Copy link
Contributor Author

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(
Copy link
Contributor

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 });
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

@maggu2810 maggu2810 merged commit caa91af into eclipse-archived:master May 26, 2017
cdjackson added a commit to cdjackson/smarthome that referenced this pull request Jun 3, 2017
* 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
@kaikreuzer kaikreuzer modified the milestone: 0.9.0 Jun 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Scheduler] Excessive use of SimpleDateFormat [Scheduler] ArrayIndexOutOfBoundsException in scheduler
6 participants