Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. public class TwoThreads {
  2. public static class Thread1 extends Thread {
  3. public void run() {
  4. System.out.println("A");
  5. System.out.println("B");
  6. }
  7. }
  8.  
  9. public static class Thread2 extends Thread {
  10. public void run() {
  11. System.out.println("1");
  12. System.out.println("2");
  13. }
  14. }
  15.  
  16. public static class ThreadAB implements Runnable{
  17. char prv;
  18. char vtor;
  19. public ThreadAB(char prv,char vtor){
  20. this.prv=prv;
  21. this.vtor=vtor;
  22. }
  23. @Override
  24. public void run() {
  25. System.out.println(prv);
  26. System.out.println(vtor);
  27. }
  28. }
  29.  
  30. public static void main(String[] args) throws InterruptedException {
  31. Thread t1=new Thread(new ThreadAB('A','B'));
  32. Thread t2=new Thread(new ThreadAB('1','2'));
  33. t1.start();
  34. t1.join();
  35. t2.start();
  36. t2.join();
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement