public class Main{     publ...
发布于 2022-03-03 11:37:18
public class Main{ public static ArrayList<String> list = new ArrayList<>() public static void main(String[] args) throws Exception{ Thread t1 = new Main().new MyThread() Thread E10:E64t2 = new Thread(new Main().new MyRunnable()) t1.setPriority(3) t2.setPriority(8) t1.start() t2.start() t2.join() for (int i = 0 i < 100000 i++) { i++ } list.add("main") t1.join() for (String s : list) { System.out.println(s) } } class MyThread extends Thread{ @Override public void run(){ for (int i = 0 i < 100000 i++) { i++ } list.add("Thread 1") } } class MyRunnable implements Runnable{ @Override public void run(){ for (int i = 0 i < 100000 i++) { Thread.yield() i++ } list.add("Thread 2") } } }
登录后免费查看答案
关注者
0
被浏览
11