Java Multitasking  «Prev  Next»

Lesson 13

Java Multitasking Conclusion

This module discussesd and explored an application that simulated a town hall meeting and performed multitasking. You learned how to create and start threads and how to supply run() methods for them.
You also learned about Java's synchronized keyword, which helps keep a thread from interfering with another thread by supplying a system of locks for objects and classes. When a thread enters a synchronized method, it acquires a lock, which stops other threads from executing the method at the same time. This can protect data that should be changed only one thread at a time.
Last, you learned about the life cycle of a thread, how to put a thread to sleep using wait(), how to wake it up again using notify(), and how to have one thread wait for another thread to complete using join().

Multithreaded Java Application

Even if you do not create a multithreaded Java application, you cannot ignore these concepts. Java technologies like swing in Core Java, Java Servlets in web applications and many Java frameworks implicitly use multithreading techniques and call your code from multiple threads. Developing safe code that works and behaves well in a multithreaded environment demands knowledge about multithreading and synchronization.
Multithreading is a complex topic and its coverage in this chapter is limited to the topics covered on the exam. This module also included an introduction to a few threading concepts that you must know to understand the module contents. For the 1Z0-804 exam, you must be able to clearly identify what is guaranteed and what is not by threads. For example, a thread is guaranteed to execute its own code in the sequence in which it is defined. But you cannot guarantee when a thread exactly starts, pauses, or resumes its execution.

Complete application

You might want to read over the complete TownHall application before moving on to make sure you understand how all the multitasking works, now that you have reached the end of this module and seen the whole picture.