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

前端 未结 10 1819
情歌与酒
情歌与酒 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 02:56

    Agree with Schildmeijer, don't override start, override run() instead.

    In fact, although start can be overridden (it's not final), it calls the native start0 method which in turn will cause the VM to call the run method (actually from the context of a native thread/process). The native start0 method has private access, so even if you overrode the start, I can't see how you could reproduce the affect.

    The client calling start() is within a thread (lets say, the main thread), it's not until the run method has done its thing that another thread will be spawned.

    Take a look at the Sun (ahem, Oracle) tutorial on threads at http://download.oracle.com/javase/tutorial/essential/concurrency/index.html, in particular the section on starting threads.

提交回复
热议问题