Advertisement
STANAANDREY

java basic threads

Oct 2nd, 2022
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. class HelloThread extends Thread {
  2.  
  3.     @Override
  4.     public void run() {
  5.         System.out.println("Hello from a thread1!");
  6.  
  7.         try {
  8.             Thread.sleep(3000);
  9.         } catch (InterruptedException e) {
  10.             throw new RuntimeException(e);
  11.         }
  12.         System.out.println("Hello from a thread2!");
  13.     }
  14.  
  15. }
  16.  
  17. public class Main {
  18.     public static void main(String[] args) {
  19.         System.out.println("Hello world!");
  20.         var helloThread = new HelloThread();
  21.         helloThread.start();
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement