62,614
社区成员
发帖
与我相关
我的任务
分享
public class TestABCD {
public static void main(String args[]) {
TestABCD test = new TestABCD();
for (int i = 0; i < 6; i++) {
ThreadTest threadTest = test.new ThreadTest();
threadTest.setName(String.valueOf(i));
Thread t = new Thread(threadTest);
t.start();
}
}
private synchronized void doSomething(String id) {
try {
System.out.println("Thread ID: " + id);
} catch (Exception e) {
e.printStackTrace();
}
}
class ThreadTest implements Runnable {
String id = "";
public void run() {
doSomething(id);
}
public void setName(String id) {
this.id = id;
}
}
}
public static void main(String args[]) {
TestABCD test = new TestABCD();
for (int i = 0; i < 6; i++) {
ThreadTest threadTest = test.new ThreadTest();
threadTest.setName(String.valueOf(i));
Thread t = new Thread(threadTest);
t.setPriority(Thread.MAX_PRIORITY - i);
t.start();
}
}
public static void main(String args[]) {
TestABCD test = new TestABCD();
for (int i = 0; i < 6; i++) {
ThreadTest threadTest = test.new ThreadTest();
threadTest.setName(String.valueOf(i));
Thread t = new Thread(threadTest);
t.start();
t.setPriority(Thread.MAX_PRIORITY - i);
}
}