请问java多线程怎么实现
展开全部
class SecondThread implements Runnable {
int i;
public void run() {
for(int i=0;i<6;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
}
}
public class TestThread2 {
public static void main(String[] args) {
SecondThread s = new SecondThread();
Thread t = new Thread(s,"子线程1");
Thread k = new Thread(s,"子线程2");
t.start();
k.start();
for(int i=0;i<4;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
}
}
int i;
public void run() {
for(int i=0;i<6;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
}
}
public class TestThread2 {
public static void main(String[] args) {
SecondThread s = new SecondThread();
Thread t = new Thread(s,"子线程1");
Thread k = new Thread(s,"子线程2");
t.start();
k.start();
for(int i=0;i<4;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询