Follow these steps to implement the example:
- Create a class called MyThreadFactory and specify that it implements the ThreadFactory interface:
public class MyThreadFactory implements ThreadFactory {
- Declare three attributes: an integer number called counter, which we will use to store the number of thread objects created, a string called name with the base name of every thread created, and a list of string objects called stats to save statistical data about the thread objects created. Also, implement the constructor of the class that initializes these attributes:
private int counter; private String name; private List<String> stats; public MyThreadFactory(String name){ counter=0; this.name=name; stats=new ArrayList<String>(); ...