This example uses java version: jdk1.6.0_01.
If you have a large project it's difficult to find all threads that are created without a name.
You may want to find and name unnamed threads from you project so you don't get:
thread-1
thread-2
thread-3
names in traces and stack dumps.
A search would have to cover all the different ways of creating threads,
including inner/anonymous class delcarations and extensions of the Thread class.
Instead of using a text search, it's possible to remove the constructors from the Thread class that do not include a name from java library.
Here is a copy of the thread class (java 1.6) that already has this done:
You can download this, rename it to Thread.class, and replace the current .class file in jre/lib/rt.jar under the java install directory.
Now it will be impossible to create an unnamed/anonymous threads in you java project.
These are the constructors that were removed from the Thread.class above using a byte code editor.
init<> ()V
init<> (Ljava/lang/Runnable;)V
init<> (Ljava/lang/ThreadGroup;Ljava/lang/Runnable;)V
This may be useful to know if you want to remove theses constructors for another java version.