One implementation of the Runnable interface uses a thread.
Here we implemented the interface with Runnabletest, created the object of the implementation class in the main function, and passed it to the
Thread's constructor, and then call the Start method. The code is as follows
public class Runnabletest implements Runnable {@Override public void run () {System.out.println (Thread.curren TThread (). GetName () + "is Running"); } public static void Main (string[] args) {runnabletest run = new Runnabletest (); Thread thread = new thread (run); Thread.Start (); }}
Two inherited threads to use a thread
Again, we can inherit the thread class and rewrite his run () method to use threads.
public class ThreadTest extends Thread {@Override public void run () {System.out.println (Thread.currentthrea D (). GetName () + "is Running"); } public static void Main (string[] args) {threadtest thread = new ThreadTest (); Thread.Start (); }}
This article is from the "11450029" blog, please be sure to keep this source http://11460029.blog.51cto.com/11450029/1763490
Threading primer, talking about thread and runnable