Note the following code. Assume that MyRunnable() is a class extending the Runna
ID: 3840640 • Letter: N
Question
Note the following code. Assume that MyRunnable() is a class extending the Runnable interface. What's the purpose of the highlighted code? public static void main(String[] args) {Thread t1 = new Thread(new MyRunnable(), "t1"); Thread t2 = new Thread(new MyRunnable(), "t2"); Thread t3 = new Thread(new MyRunnable(), "t3"); t1. start (); t2. start(); try {t1.join(); t2-join();} catch (InterruptedException e) {e.printStackTrace();} t3.start();} a. Forces program to wait until threads t1 & t2 are complete before starting t3. b. Forces program to wait until thread t1 is complete before starting t2. c. Threads t1 and t2 are potentially running concurrently d. Thread t2 isn't started until thread t1 is complete e. Answers A & C Thread.sleep (4000) will unscheduled the thread from execution for: a. 4000 seconds b. 4000 cycles c. 4 seconds d. 4 cycles Which method(s) have been deprecated in the Thread class? a. Start () b. Sleep () c. Stop () d. Interrupt ()Explanation / Answer
1. join method is used to stop the running thread till thread callimg join is completed ..
so answer is b, the program will wait until thread t1 is complete before starting t2.
after that it will wait for t2 to complete before next statement execution..
2. thread.sleep takes time in milliseconds ... so 4000 means 4 seconds here
so answer is c)
3. c) stop()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.