QUIZ COSC 341 q 1205 Fall 2017 Answer the following. Computer use is ok 1. What is run() (answer with respect to threads or runnables) 2. What does sleep() do? 3. Why does the code say Thread.sleep()? I.e., what happens? 4. In ThreadClassDemo, a thread is instantiated with new Thread(hello) 4.a. What is hello? 4.b Give a copy of the constructor documentation from Java API for new Thread(hello) -------------------------------------------------------------------- Solutions 1. run() gives the executable code of a thread. If the code extends Thread, then run() is almost always supplied to override the run() that the Thread class had to supply (because Thread implements the interface Runnable, and Runnable requires a run() ). 2. sleep() puts the executing thread to sleep for the specified time. E.g., sleep(50) puts the thread to sleep for 50ms. 3. Thread.sleep() can be said becuse sleep is a static method of the Thread class. 4 a). hello is a Runnable object b) public Thread (Runnable target) "Allocates a new Thread object. This constructor has the same effect as Thread (null, target, gname), where gname is a newly generated name.