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

📄 threadtester.java

📁 Java语言是目前最流行
💻 JAVA
字号:
//继承Thread类
class CountThread extends Thread
{
	private	int start;//发起
	private int finish;//完成
	
	public CountThread(int from,int to)
	{//构造函数
		this.start = from;
		this.finish = to;
	}
	public void run()
	{
		System.out.println(this.getName()+" static executing...");
		for(int i=start;i<=finish;i++)
		{
			System.out.print(i + "  ");	
		}	
		System.out.print(this.getName()+" finished executing.");
	}
}
public class ThreadTester
{
	static public void main(String[] args)
	{
		CountThread thread1 = new CountThread(1,10);
		CountThread thread2 = new CountThread(20,30);
		thread1.start();
		thread2.start();
	}	
}
//运行时两次结果不一样
/*
	1次、1和2线程一起运行
	2次、1线程结束后2线程才运行。
*/

⌨️ 快捷键说明

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