smiklosovic commented on code in PR #4831: URL: https://github.com/apache/cassandra/pull/4831#discussion_r3303812825
########## src/java/org/apache/cassandra/concurrent/CassandraThread.java: ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.concurrent; + +import org.apache.cassandra.metrics.ThreadLocalMetrics; + +import io.netty.util.concurrent.FastThreadLocalThread; + +public class CassandraThread extends FastThreadLocalThread +{ + private ThreadLocalMetrics threadLocalMetrics; + private ExecutorLocals executorLocals; + + public CassandraThread(ThreadGroup group, Runnable target, String name) + { + super(group, target, name); + } + + public CassandraThread() + { + super(); + } + + public ThreadLocalMetrics getThreadLocalMetrics() + { + ThreadLocalMetrics current = threadLocalMetrics; + if (current != null) + return current; + + threadLocalMetrics = ThreadLocalMetrics.create(); + return threadLocalMetrics; + } + + public ExecutorLocals getExecutorLocals() + { + ExecutorLocals current = executorLocals; + if (current != null) + return current; + + executorLocals = ExecutorLocals.none(); + return executorLocals; + } + + public void setExecutorLocals(ExecutorLocals executorLocals) + { + this.executorLocals = executorLocals; + } + + public ExecutorLocals replaceExecutorLocals(ExecutorLocals newExecutorLocals) + { + ExecutorLocals current = executorLocals; + if (current != newExecutorLocals) + executorLocals = newExecutorLocals; + + return current != null ? current : ExecutorLocals.none(); + } + + public void doRun() Review Comment: This is easy to get wrong, like just running doRun() with the work and not calling run() at all. It just feels strange to have empty doRun() like this. doRun might be abstract and we would have a class like `DefaultCassandraThread` which would just have this doRun() explicitly empty. Just a suggestion really, maybe just java doc would do it. Some documentation would not be bad to add either, it is a bit confusing what is called where. `run` calls `super.run` which actually runs `Runnable target` we pass to this constructor, then doRun() is supposed to do what exactly? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

