Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. package threadspriority;
  2.  
  3. public class ThreadsPriority {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. SimpleThread sthread1 = new SimpleThread("Jeremy", "Lucas");
  8. SimpleThread sthread2 = new SimpleThread("Big", "giB");
  9. SimpleThread sthread3 = new SimpleThread("Gay", "isOkay");
  10.  
  11. Thread thrd1 = new Thread(sthread1);
  12. Thread thrd2 = new Thread(sthread2);
  13. Thread thrd3 = new Thread(sthread3);
  14.  
  15. thrd1.start();
  16. thrd2.start();
  17. thrd3.start();
  18.  
  19. }
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. package threadspriority;
  30.  
  31. public class SimpleThread implements Runnable {
  32.  
  33. String s1, s2;
  34.  
  35. public SimpleThread(String s1, String s2) {
  36. this.s1 = s1;
  37. this.s2 = s2;
  38. }
  39.  
  40. public void print() {
  41. for (int i = 0; i < 5; i++) {
  42. System.out.println(this.s1);
  43. try{
  44. Thread.sleep(500);
  45. }catch(InterruptedException e){
  46. }
  47.  
  48. System.out.println(this.s2);
  49. }
  50. }
  51.  
  52. @Override
  53. public void run() {
  54. this.print();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement