Answers for "thread with lambda java"

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
1

java thread lambda

Thread t = new Thread(new Runnable() {
    public void run() {
        // your code here ...
    }
});
Posted by: Guest on August-07-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language