1 / 40

10. Multithreading

10. Multithreading. Java. public class SumTest { public static void main(String a1[]) { int a, b, sum; a = Integer.parseInt (a1[0]); b = Integer.parseInt (a1[1]); sum = a + b ; // 두 수를 더하는 부분입니다 System.out.println (" 두수의 합은 " + sum + " 입니다 "); }

prisca
Download Presentation

10. Multithreading

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10. Multithreading Java public class SumTest { public static void main(String a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두 수를 더하는 부분입니다 System.out.println("두수의 합은 " + sum + "입니다"); } }

  2. Threads Concept Multiple threads on multiple CPUs Multiple threads sharing a single CPU

  3. Thread Class • java.lang Package Thread() Thread(String s) Thread(Runnable r) Thread(Runnable r, String s)

  4. Method

  5. StateMachine diagram

  6. Thread states • New • Runnable(ready) • Running(executing) • Waiting • Dead(finished)

  7. Thread Class

  8. Runnable Interface

  9. Example

  10. Exercises

  11. Java : 1 Java : 2 Java : 3 Java : 4 Java : 5 Java : 6 Java : 7 Java : 8 Java : 9 Java : 10

  12. Exercises

  13. Java : 1 Java : 2 Java : 3 Java : 4 Java : 5 Java : 6 Java : 7 Java : 8 Java : 9 Java : 10

  14. Exercises

  15. 1: Thread1 1: Thread2 2: Thread1 2: Thread2 3: Thread1 3: Thread2 4: Thread1 4: Thread2 5: Thread1 5: Thread2 6: Thread1 6: Thread2 7: Thread1 7: Thread2 8: Thread1 8: Thread2 9: Thread1 9: Thread2 10: Thread1 10: Thread2 End: Thread1 End: Thread2

  16. 1: Thread2 1: Thread1 2: Thread2 2: Thread1 3: Thread2 3: Thread1 4: Thread2 4: Thread1 5: Thread2 5: Thread1 6: Thread2 6: Thread1 7: Thread2 7: Thread1 8: Thread2 8: Thread1 9: Thread2 9: Thread1 10: Thread2 10: Thread1 End: Thread2 End: Thread1

  17. setPriority() • Changes the priority of this thread.

  18. Excercises

  19. Excercises

  20. 1 : Third Thread : 1 1 : First Thread : 5 1 : Second Thread : 10 2 : Second Thread : 10 3 : Second Thread : 10 4 : Second Thread : 10 2 : First Thread : 5 3 : First Thread : 5 4 : First Thread : 5 5 : First Thread : 5 2 : Third Thread : 1 5 : Second Thread : 10 3 : Third Thread : 1 4 : Third Thread : 1 5 : Third Thread : 1

  21. 실습예제

  22. 실습예제

  23. ***** Start ***** ***** End***** 1 : Thread2 1 : Thread1 2 : Thread2 2 : Thread1 3 : Thread2 3 : Thread1 End : Thread2 End : Thread1

  24. 5 스레드의 시작과 종료 • 실습예제

  25. 실습예제

  26. ***** Start ***** 1 : Thread1 1 : Thread2 2 : Thread1 2 : Thread2 3 : Thread1 3 : Thread2 End : Thread1 End : Thread2 ***** End *****

  27. synchronized Method Critical section unlock Critical section 329 page

  28. 330 page

  29. Excercises

  30. 실습예제

  31. 실습예제

  32. Donator3 : 0 Donator3 : 1 Donator1 : 0 Donator4 : 0 ......... Donator5 : 62 Donator3 : 124 Donator1 : 126 Donator4 : 125 Donator2 : 62 Total : 504000

  33. Donator1 : 0 Donator1 : 1 Donator1 : 2 Donator3 : 0 ......... Donator2 : 42 Donator3 : 102 Donator5 : 92 Donator1 : 62 Donator2 : 43 Total : 503000

  34. java.lang.Object Class - wait(), notify(), notifyAll()

  35. wait( ), notify( ), notifyAll( ) Method 335 page

  36. Excercises

  37. Excercises

  38. Excercises

  39. Producer ########## : Produce 0 Consumer########## : Consume 0 Producer ########## : Produce 1 ............................ Consumer########## : Consume 7 Producer ########## : Produce 8 Consumer########## : Consume 8 Producer ########## : Produce 9 Consumer########## : Consume 9

More Related