You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "m1a2st (via GitHub)" <gi...@apache.org> on 2024/06/03 16:49:51 UTC
[PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
m1a2st opened a new pull request, #16179:
URL: https://github.com/apache/kafka/pull/16179
https://issues.apache.org/jira/browse/KAFKA-16879
I use the static inner class to implement to singleton pattern.
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
Posted by "gharris1727 (via GitHub)" <gi...@apache.org>.
gharris1727 commented on code in PR #16179:
URL: https://github.com/apache/kafka/pull/16179#discussion_r1625208358
##########
clients/src/main/java/org/apache/kafka/common/utils/SystemTime.java:
##########
@@ -26,6 +26,18 @@
*/
public class SystemTime implements Time {
+ /**
+ * use the static inner class to implement the singleton pattern
+ * to avoid the overhead of synchronization
Review Comment:
Can you explain this comment? I don't know what it's referring to, as none of this code is synchronized.
The static inner class seems to be a lazy initialization trick, which is ineffective here (due to Time.SYSTEM) and unneeded (since the SystemTime constructor is very cheap).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
Posted by "gharris1727 (via GitHub)" <gi...@apache.org>.
gharris1727 commented on code in PR #16179:
URL: https://github.com/apache/kafka/pull/16179#discussion_r1625205338
##########
clients/src/main/java/org/apache/kafka/common/utils/Time.java:
##########
@@ -30,7 +30,7 @@
*/
public interface Time {
- Time SYSTEM = new SystemTime();
+ Time SYSTEM = SystemTime.getInstance();
Review Comment:
Hey, is there a reason this isn't the canonical singleton instance? Why would we want two different ways to get the singleton `Time.SYSTEM` and `SystemTime.getInstance()`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #16179:
URL: https://github.com/apache/kafka/pull/16179#discussion_r1625215483
##########
clients/src/main/java/org/apache/kafka/common/utils/Time.java:
##########
@@ -30,7 +30,7 @@
*/
public interface Time {
- Time SYSTEM = new SystemTime();
+ Time SYSTEM = SystemTime.getInstance();
Review Comment:
You are right, I should deprecate `Time SYSTEM` this property, and use `SystemTime.getInstance()` to instead it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st closed pull request #16179: KAFKA-16879: SystemTime should use singleton mode
URL: https://github.com/apache/kafka/pull/16179
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #16179:
URL: https://github.com/apache/kafka/pull/16179#discussion_r1625217653
##########
clients/src/main/java/org/apache/kafka/common/utils/SystemTime.java:
##########
@@ -26,6 +26,18 @@
*/
public class SystemTime implements Time {
+ /**
+ * use the static inner class to implement the singleton pattern
+ * to avoid the overhead of synchronization
Review Comment:
True, `SystemTime` is very cheap, but I think that don't use double-checked locking to implement the singleton pattern, maybe I should remove this comment is more better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16879: SystemTime should use singleton mode [kafka]
Posted by "gharris1727 (via GitHub)" <gi...@apache.org>.
gharris1727 commented on code in PR #16179:
URL: https://github.com/apache/kafka/pull/16179#discussion_r1625228386
##########
clients/src/main/java/org/apache/kafka/common/utils/Time.java:
##########
@@ -30,7 +30,7 @@
*/
public interface Time {
- Time SYSTEM = new SystemTime();
+ Time SYSTEM = SystemTime.getInstance();
Review Comment:
I would be inclined to keep the existing `Time.SYSTEM` and avoid the deprecation. SystemTime can then be package-local entirely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org