Java Threads

It is possible in Java for an individual program to simultaneously perform more than one task, or thread. All the programs discussed in this book so far implicitly use just one thread. Such a program is described as single threaded. Threads cannot exist independently; they always exist within the context of a program. A Java program can have any number of associated threads that are created explicitly; if a program has more than one associated thread, it is said to be multithreaded. Threads are sometimes described as execution contexts.

It is possible to delay execution of a thread: this feature of threads is typically used in animation. Multithreading is often used in applets that perform a number of independent tasks, one or more of which performs some lengthy initialization. With multithreading, the applet can perform some tasks while the lengthy tasks continue in the background. Typically, these lengthy tasks include loading images or accessing large volumes of data. A common use of multithreading is in client–server applications where the server may use one thread for each client.

No comments:

Post a Comment