Java中的线程是否应该被命名以便于调试? [英] Should threads in Java be named for easier debugging?

查看:97
本文介绍了Java中的线程是否应该被命名以便于调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中线程命名的最佳实践是什么?是否有任何命名约定?

What are the best practices around thread naming in Java? Are there any naming conventions to follow?

推荐答案

我会说一般的最佳实践是选择好名字,这个适用于变量,方法,计算机,甚至可能是儿童(只要问我的儿子Gerund Extravagaza Smith)。

I'd say that a general Best Practice is "choose good names", this applies to variables, methods, computers, possibly even children (just ask my son Gerund Extravagaza Smith).

所以是的,如果可能的话,为你的线程选择有意义的名字。

So yes, choose meaningful names for your threads if possible.

假设我们要求文件或计算机的命名约定。您是否期望有一个普遍适用的答案?我认为您需要根据自己创建的线程生成自己的约定。

Suppose we asked for a naming convention for files or computers. Would you expect there to be a generally applicable answer? I think that you need to generate a convention of your own that makes sense with the kind of threads your create.

我会遵循以下一般原则:

I would follow these general principles:


  • 简短,让我们避免reallyLongNamesWithManyProbablyIrreleventClauses-Thread-01

  • 有意义,但接受你可能有一个线程池作业-01,job-02

  • 最重要的部分首先

  • Short, lets avoid reallyLongNamesWithManyProbablyIrreleventClauses-Thread-01
  • Meaningful, but accept that you may have a pool of threads job-01, job-02
  • Most significant part first

01-http-Listener 
01-rmi-Listener
02-http-Listener

倾向于严重排序所以更喜欢Listener-http-01

tends to sort badly so prefer Listener-http-01

这篇关于Java中的线程是否应该被命名以便于调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆