Reputation: 14707
I have various Thread in my java application with syntax
new Thread(this).start();
When I performed Code Audit using Code Pro I have got following message
Thread declare without a name.
I wants to know what does it mean and is it ok if I change the declaration to
new Thread(this,this.getName()).start();
What is the difference between them and their impact. Thanks in advance.
Upvotes: 3
Views: 467
Reputation: 310936
The difference is that the thread now has the name you give it instead of a default name. Apparently someone considers that important enough to hold up an audit. I certainly do not.
Upvotes: 1
Reputation: 236014
It's just Code Pro's polite way of reminding you that a thread should have an identifying name, for easier debugging if it comes to that. It doesn't have any more "impact" beyond that, it's simply a good programming practice. This should work:
new Thread(this, "an identifying name").start();
Notice that this.getName()
will only work if you already defined a name to be returned by getName()
in the current class.
Upvotes: 4