⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extendthreaddemo.java

📁 Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用安全
💻 JAVA
字号:
// Chapter 7, Listing 1
public class ExtendThreadDemo extends java.lang.Thread
{
	int threadNumber;

	public ExtendThreadDemo ( int num )
	{
		// Assign to member variable
		threadNumber = num;
	}

	// Run method is executed when thread first started
	public void run()
	{
		System.out.println ("I am thread number " + threadNumber);

		try
		{
			// Sleep for five thousand milliseconds (5 secs), to simulate work being done
			Thread.sleep(5000);
		}
		catch (InterruptedException ie) {}

		System.out.println (threadNumber + " is finished!");
	}


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

		// Create first thread instance
		Thread t1 = new ExtendThreadDemo(1);

		System.out.println ("Creating thread 2");

		// Create second thread instance
		Thread t2 = new ExtendThreadDemo(2);

		/*
		// Make both threads daemon threads
		t1.setDaemon(true); t2.setDaemon(true);
		*/

		// Start both threads
		t1.start(); t2.start();

		/*
		try
		{
			// Sleep for one second, to allow threads
			// time to display first message
			Thread.sleep(1000);
		}
		catch (InterruptedException ie) {}
		*/
	}
}

⌨️ 快捷键说明

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