runnablethreaddemo.java

来自「Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用」· Java 代码 · 共 34 行

JAVA
34
字号
// Chapter 7, Listing 2
public class RunnableThreadDemo implements java.lang.Runnable
{
	// Run method is executed when thread first started
	public void run()
	{
		System.out.println ("I am an instance of the java.lang.Runnable interface");
	}


	// Main method to create and start threads
	public static void main(String args[])
	{
		System.out.println ("Creating runnable object");

		// Create runnable object
		Runnable run = new RunnableThreadDemo();

		// Create a thread, and pass the runnable object
		System.out.println ("Creating first thread");
		Thread t1 = new Thread (run);


		// Create a second thread, and pass the runnable object
		System.out.println ("Creating second thread");
		Thread t2 = new Thread (run);

		// Start both threads
		System.out.println ("Starting both threads");
		t1.start(); t2.start();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?