Question 1. Write a java program to execute multiple tasks concurrently and with some elements of thread control using the available methods (for example the use of sleep() and wait() methods). · Demonstrate the use of sleep() method to control the execution duration of each thread. Provide a different duration for each of the thread to show the effect to the output. · Provide user control to stop the thread using the appropriate approach in stopping the thread. · Briefly discuss the function of the sleep() method and its difference(s) with the wait() method.

EUMEC4 The Asker · Computer Science

1. Write a java program to execute multiple tasks concurrently and with some elements of thread control using the available methods (for example the use of sleep() and wait() methods).

· Demonstrate the use of sleep() method to control the execution duration of each thread. Provide a different duration for each of the thread to show the effect to the output.

· Provide user control to stop the thread using the appropriate approach in stopping the thread.

· Briefly discuss the function of the sleep() method and its difference(s) with the wait() method.

More
Community Answer
MUGSEI

1)  package demotest; public class multiple_threads implements Runnable { @Override public void run() { } public static void main(String[] args) { Thread thread1 = new Thread(); thread1.start(); try { thread1.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } thread1.setPriority(1); int priority = thread1.getPriority(); System.out.println(priority); System.out.println("Thread Running"); } } sleep method() class SleepThread extends Thread  {        public void run()    {            for(int i=1;i<5;i++)   {                try  {                  Thread.sleep(1000);              }catch(InterruptedException e){System.out.println(e);}                System.out.println(Thread.currentThread().getName() + "   : " + i);            }        }    } class Main{     public static void main(String args[])      {          SleepThread thread_1 = new SleepThread();            SleepThread thread_2 = new SleepThread();       &# ... See the full answer