Follow these steps to implement the example:
- Create a class named MyThread that extends the Thread class:
public class MyThread extends Thread {
- Declare three private Date attributes named creationDate, startDate, and finishDate:
private final Date creationDate; private Date startDate; private Date finishDate;
- Implement a constructor of the class. It receives the name and the Runnable object to be executed as parameters. Initialize the creation date of the thread:
public MyThread(Runnable target, String name ){ super(target,name); creationDate = new Date(); }
- Implement the run() method. Store the start date of the thread, call the run() method of the parent class, and store the finish date of the execution: ...