Answers for "java lamda expression thread"

1

java anonymous thread lambda

public class LambdaThreadTest {
   public static void main(String args[]) {
      // Child thread
      new Thread(() -> { // Lambda Expression
         for(int i=1; i <= 5; i++) {
            System.out.println("Child Thread: "+ i);
            try {
               Thread.sleep(500);
            } catch(Exception e) {
               e.printStackTrace();
            }
         }
      }).start();
      // Main Thead
      for(int j=1; j < 5; j++) {
         System.out.println("Main Thread: "+ j);
         try {
            Thread.sleep(500);
         } catch(Exception e) {
            e.printStackTrace();
         }
      }
   }
}
Posted by: Guest on September-20-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language