为什么出错啊,线程,,帮忙啊,简单非常啊,
package com.abc.www;
public class ThreadDemo4 {
public static void main(String[] args) {
ThreadTest t = new ThreadTest();
t.start();
t.start();
t.start();
t.start();
}
}
class ThreadTest extends Thread {
private int tickets = 100;
public void run() {
while (true) {
if (tickets > 0)
System.out.println(Thread.currentThread().getName()
+ "is saling tickeer " + tickets--);
}
}
}
------解决方案--------------------ThreadTest t = new ThreadTest();
t.start();
t.start();
t.start();
t.start();
一个线程只要启动一次(指thread.start()一次就行了)
------解决方案--------------------报什么错啊.
------解决方案--------------------ThreadTest t = new ThreadTest();
t.start();
t.start();
t.start();
t.start();
---------->
new ThreadTest().start();
new ThreadTest().start();
new ThreadTest().start();
new ThreadTest().start();