From what time I've spent with threads in Java, I've found these two ways to write threads:
(从什么时候开始在Java中使用线程开始,我发现了以下两种编写线程的方法:)
With implements Runnable
:
(与implements Runnable
:)
public class MyRunnable implements Runnable {
public void run() {
//Code
}
}
//Started with a "new Thread(new MyRunnable()).start()" call
Or, with extends Thread
:
(或者,使用extends Thread
:)
public class MyThread extends Thread {
public MyThread() {
super("MyThread");
}
public void run() {
//Code
}
}
//Started with a "new MyThread().start()" call
Is there any significant difference in these two blocks of code ?
(这两个代码块有什么显着区别吗?)
ask by user65374 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…