how to override thread.start() method in java?

前端 未结 10 1824
情歌与酒
情歌与酒 2020-12-03 02:07

I need to implement thread.start() method in my java code. Please let me know through an example of overriding of thread.start() method and how it works?

10条回答
  •  伪装坚强ぢ
    2020-12-03 03:01

    class Worker implements Runnable{

    public void run(){ if("foo"){ runFoo(); } else { runBar(); } }

    private void runFoo(){ // something }

    private void runBar(){ // else }

    }

    I'm pretty sure, you needn't to overwrite the start-Method.

    By the way: Take al look at java.util.concurrent.Callable

    http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Callable.html

提交回复
热议问题