QUESTO IST Consider the following code for a multi-threading example that implements Runnable. The code initializes 2 threads and runs them public class MidtermExample implements Runnable public void run() for(int i=1;i<=5;i++){ tryl Thread.sleep(1

匿名用户 最后更新于 2021-11-29 17:10 计算机类Computing


QUESTO IST Consider the following code for a multi-threading example that implements Runnable. The code initializes 2 threads and runs them public class MidtermExample implements Runnable public void run() for(int i=1;i<=5;i++){ tryl Thread.sleep(1000); }catch(interruptedException ie) ie.printStackTrace(); } System.out.println(i); } } public static void main(String argstix Thread thread1 = new Thread(new MidtermExample(), "thread1"); Thread thread2 = new Thread(new MidtermExample(), "thread2"); thread1.run(); thread2.run(); } 自创 De 40 a) What would be the output of the code? (1 Mark) 2 b) Did multithreading take place? Justify and explain your answer. (2 Marks)

已邀请: