2021-04-28 16:49:39 +02:00
|
|
|
Naming a thread won't make it run faster or more reliably, but it will make it easier to deal with if you need to debug the application.
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
Thread t1 = new Thread(new Runnable() {
|
|
|
|
// ...
|
|
|
|
};
|
|
|
|
t1.start(); // Noncompliant; this thread wasn't named
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
Thread t1 = new Thread(new Runnable() {
|
|
|
|
// ...
|
|
|
|
};
|
|
|
|
t1.setName("t1");
|
|
|
|
t1.start();
|
|
|
|
----
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
|
|
|
ifdef::rspecator-view[]
|
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::comments-and-links.adoc[]
|
|
|
|
endif::rspecator-view[]
|