wenjin272 commented on code in PR #1028: URL: https://github.com/apache/flink-agents/pull/1028#discussion_r3826957674
########## runtime/src/main/java/org/apache/flink/agents/runtime/async/AsyncExecutorThreadFactory.java: ########## @@ -0,0 +1,49 @@ +/* + * 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.flink.agents.runtime.async; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * {@link ThreadFactory} for the Flink Agents Java async executor, producing descriptive, + * collision-resistant thread names of the form {@code + * flink-agents-java-async-<pool-id>-thread-<worker-id>}. + * + * <p>Default executor names such as {@code pool-N-thread-M} make Flink Agents async workers hard to + * attribute in TaskManager thread dumps and profiler output, where many unrelated pools coexist. + * The pool id is process-unique so multiple executor instances in one TaskManager remain + * distinguishable; only the name changes — thread priority and daemon status follow the default + * factory behavior. + */ +public final class AsyncExecutorThreadFactory implements ThreadFactory { + + private static final AtomicInteger POOL_ID = new AtomicInteger(); + + private final String namePrefix; + private final AtomicInteger workerId = new AtomicInteger(); + + public AsyncExecutorThreadFactory() { + this.namePrefix = "flink-agents-java-async-" + POOL_ID.incrementAndGet() + "-thread-"; + } + + @Override Review Comment: The PR states that only the thread name changes, but `new Thread(...)` inherits the daemon status and priority of the calling thread, unlike the previous default thread factory, which normalizes them to non-daemon and `NORM_PRIORITY`. Could we delegate thread creation to `Executors.defaultThreadFactory()` to preserve the existing execution semantics? ########## runtime/src/main/java/org/apache/flink/agents/runtime/async/AsyncExecutorThreadFactory.java: ########## @@ -0,0 +1,49 @@ +/* + * 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.flink.agents.runtime.async; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * {@link ThreadFactory} for the Flink Agents Java async executor, producing descriptive, + * collision-resistant thread names of the form {@code + * flink-agents-java-async-<pool-id>-thread-<worker-id>}. + * + * <p>Default executor names such as {@code pool-N-thread-M} make Flink Agents async workers hard to + * attribute in TaskManager thread dumps and profiler output, where many unrelated pools coexist. + * The pool id is process-unique so multiple executor instances in one TaskManager remain + * distinguishable; only the name changes — thread priority and daemon status follow the default + * factory behavior. + */ +public final class AsyncExecutorThreadFactory implements ThreadFactory { + + private static final AtomicInteger POOL_ID = new AtomicInteger(); Review Comment: If we use `Executors.defaultThreadFactory()`, the generated thread name already contains the pool and worker IDs (`pool-N-thread-M`). Could we simply prepend `flink-agents-java-async-` to that name instead of maintaining separate `POOL_ID` and `workerId` counters? The resulting name would be `flink-agents-java-async-pool-N-thread-M`. -- 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]
