How to correctly get thread name in Java?

前端 未结 4 1349
醉酒成梦
醉酒成梦 2021-02-03 23:38

I have this class for creating a thread in Java

package org.vdzundza.forms;

import java.awt.Graphics;
import java.awt.Graphics2D;

public class DrawThread exten         


        
4条回答
  •  迷失自我
    2021-02-04 00:11

    You are passing an instance of your DrawThread to a Thread(Runnable) constructor. It doesn't care that your class extends Thread; it only cares that it implements Runnable.

    The thread that gets started is the one created by new Thread(...)—and you didn't set the name on that one.

    In general, extending Thread is bad practice and should always be avoided. You are already almost there because you don't start the instance of your class, but pass it to a separate Thread instance.

提交回复
热议问题