Skip to content

Is LoggingCache thread safe? #171

Open
@ronaldploeger

Description

@ronaldploeger

Hi,

shouldn' LoggingCache instead of using int for the members 'request' and 'hits'

protected int requests = 0;
protected int hits = 0;

be using AtomicInteger (or probably even better AtomicLong) to be thread safe?

Best regards,
Ronald

Activity

emacarron

emacarron commented on Apr 1, 2014

@emacarron
Member

Hi Ronald.

Considering that that counters are just for statistics and the low probabibity of a collision I would say that is better to accept a bit of "vagueness" instead of adding a lock.

ronaldploeger

ronaldploeger commented on Apr 1, 2014

@ronaldploeger
Author

Hi Eduardo,

could be that you are right. Hard to tell without real testing how much "vagueness" this introduces and if using an AtomicInteger would notably degrade performance.

If no AtomicInteger is used I guess at least the members should be made volatile - then at least the visibility problem would be addressed.

Best,
Ronald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprove a feature or add a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @emacarron@ronaldploeger

      Issue actions

        Is LoggingCache thread safe? · Issue #171 · mybatis/mybatis-3