当前下载的版本
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

随后安装eclipse


附一个简单的多线程例子
public class Hello_Java {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello Java and Hello World");
UserThread t1,t2,t3,t4;
t1=new UserThread("1");
t2=new UserThread("2");
t3=new UserThread("3");
t4=new UserThread("4");
t1.start();
t2.start();
t3.start();
t4.start();
}
}
class UserThread extends Thread{
int sleeptime;
public UserThread(String id) {
super(id);
sleeptime=(int)(Math.random()*1000);
System.out.println("线程号: "+getName()+",睡眠"
+sleeptime+"毫秒");
}
public void run(){
try{
Thread.sleep(sleeptime);
}catch(InterruptedException e) {
System.err.println("error"+e.toString());
}
System.out.println("运行的线程是:"+getName());
}
}

路漫漫其修远兮,吾将上下而求索!
本文介绍了如何使用Java创建和启动多个线程,并提供了一个具体的多线程应用实例。通过继承Thread类并重写run方法,可以实现线程的自定义行为。文章还展示了如何设置线程的睡眠时间来模拟并发执行的场景。

被折叠的 条评论
为什么被折叠?



