cs-434: object-oriented programming using java week 8
DESCRIPTION
CS-434: Object-Oriented Programming Using Java Week 8. Dr. Jesús Borrego Adjunct Faculty Regis University. Class Outline. Review of Final Project Key Terms Concurrency and Multithreading Questions on Final Final Exam Questions?. Key Terms. Multithread – múltiples hilos Thread - Hilo. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/1.jpg)
scis.regis.edu ● [email protected]
CS-434: Object-Oriented Programming Using Java
Week 8
Dr. Jesús BorregoAdjunct FacultyRegis University
1
![Page 2: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/2.jpg)
Class Outline•Review of Final Project•Key Terms•Concurrency and Multithreading•Questions on Final•Final Exam•Questions?
2
![Page 3: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/3.jpg)
Key Terms
• Multithread – múltiples hilos• Thread - Hilo
3
![Page 4: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/4.jpg)
Concurrency
•Performing more than one task at the same time
•Can be done either by multiple processes managed by the OS or by multiple threads running under a single process
•We’ll examine Java’s approach to threads
4
![Page 5: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/5.jpg)
Concurrency in multiple CPUs
5
![Page 6: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/6.jpg)
Threads
6
![Page 7: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/7.jpg)
Thread States
7
![Page 8: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/8.jpg)
Thread Priorities
•Public static final int MAX_PRIORITY▫Defines the highest priority that can be
assigned to a thread•Public static final int MIN_PRIORITY
▫Defines the lowest priority that can be assigned to a thread
•Public static final int NORM_PRIORITY▫Defines the normal, default priority that is
assigned to a thread
8
![Page 9: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/9.jpg)
Thread Priorities (Cont’d)•On Windows, the priorities typically range
from 1-10, (10 > 1, 5 is normal)•Other platforms use different values•Highest priority threads execute before
lower priority▫i.e., threads of lower priority must wait for
higher priority threads to relinquish the CPU before they (the lower priority threads) can run.
•Threads of the same priority are allocated CPU time slices in a “round robin” fashion.
9
![Page 10: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/10.jpg)
Thread Management
•Java provides three techniques for creating threads: ▫class inheritance▫interface implementation▫timer for scheduled events
•Thread Class
10
![Page 11: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/11.jpg)
Thread Class
•The two most important methods of class Thread are run() and start()
•Method run() is used to define the high-level coding logic of a thread, which is provided by you, the developer, either through inheritance or with an implementation of interface Runnable
•When method start() is called, it notifies the JVM to launch a new thread whose entry point is method run()
11
![Page 12: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/12.jpg)
Thread Inheritance
12
•Create a class that extends Thread
•In main:
![Page 13: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/13.jpg)
Activity 1
•Port scan and threads in Java (16:50 min): http://www.youtube.com/watch?v=FpT2fJlBSjU
13
![Page 14: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/14.jpg)
Questions on material covered
14
![Page 15: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/15.jpg)
Demo of Final Project
15
![Page 16: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/16.jpg)
Final Exam
•Due Tuesday by midnight•Submit to WorldClass as a single zip file
containing the Word document and a folder with the entire NetBeans project
16
![Page 17: CS-434: Object-Oriented Programming Using Java Week 8](https://reader030.vdocuments.mx/reader030/viewer/2022033104/56812c70550346895d9107e6/html5/thumbnails/17.jpg)
Questions?
17