Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java - Provide a very short quick comment on each area with /*comment*/ listed e

ID: 3880162 • Letter: J

Question

Java - Provide a very short quick comment on each area with /*comment*/ listed explaining what the code is doing

public class CreateThreadGroups
{
   public CreateThreadGroups() {
       /* Comment Here */
       ThreadGroup alpha = new ThreadGroup("alpha");
       ThreadGroup beta = new ThreadGroup("beta");
       ThreadGroup theta = new ThreadGroup(alpha, "theta");

       /* Comment Here */  
       (new Thread(alpha, new GroupWorker())).start();
       (new Thread(alpha, new GroupWorker())).start();
       (new Thread(alpha, new GroupWorker())).start();
       (new Thread(beta, new GroupWorker())).start();
       (new Thread(theta, new GroupWorker())).start();
       (new Thread(theta, new GroupWorker())).start();
   }

   class GroupWorker implements Runnable
   {
       public void run() {
           while (true) {
               try {
                   Thread.sleep(1000);
                   for (int i = 0; i < 1000000; i++)
                       ;
               }
               catch (InterruptedException ie) { }
           }
       }
   }
}

Explanation / Answer

public class CreateThreadGroups
{
   public CreateThreadGroups() {
       /* Creating three ThreadGroups “alpha”,”beta”,”theta” to group threads.*/
       ThreadGroup alpha = new ThreadGroup("alpha");
       ThreadGroup beta = new ThreadGroup("beta");
       ThreadGroup theta = new ThreadGroup(alpha, "theta");

       /* Creating threads in each threadgroup. First argument of thread class constructor is the threadgroup name. * Second argument is the Runnable implemented class. Hence, creating anonymous threads and starting it */

       (new Thread(alpha, new GroupWorker())).start();
       (new Thread(alpha, new GroupWorker())).start();
       (new Thread(alpha, new GroupWorker())).start();
       (new Thread(beta, new GroupWorker())).start();
       (new Thread(theta, new GroupWorker())).start();
       (new Thread(theta, new GroupWorker())).start();
   }

   class GroupWorker implements Runnable
   {
       public void run() {
           while (true) {
               try {
                   Thread.sleep(1000);
                   for (int i = 0; i < 1000000; i++)
                       ;
               }
               catch (InterruptedException ie) { }
           }
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote