Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. package thread;
  2.  
  3. public class Main {
  4.  
  5. public static class MyThread implements Runnable
  6. {
  7. public void run()
  8. {
  9. for(int i=0; i<10; i++)
  10. {
  11. String s = Thread.currentThread().getName();
  12. System.out.println(s);
  13. try
  14. {
  15. Thread.sleep(50);
  16. }
  17. catch(Exception e)
  18. {
  19.  
  20. }
  21. }
  22. }
  23. }
  24.  
  25. public static void main(String[] args) {
  26. // TODO Auto-generated method stub
  27. Thread t1 = new Thread(new MyThread(), "Ping");
  28. Thread t2 = new Thread(new MyThread(), "Pong");
  29. t1.setPriority(Thread.MAX_PRIORITY);
  30. t2.setPriority(Thread.MIN_PRIORITY);
  31. t1.start();
  32. t2.start();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement