Unit 4 - LMS
Unit 4 - LMS
Differences between multi-threading and multitasking, thread life cycle, creating threads,
synchronizing threads, Inter-thread communication, daemon threads, thread groups. Generic
Programming – Generic classes – generic methods – Bounded Types – Restrictions and Limitations.
Differences between multi-threading and
multitasking
Differences between multi-threading and
multitasking
Differences between multi-threading and
multitasking
Differences between multi-threading and
multitasking
Differences between multi-threading and
multitasking
Differences between multi-threading and
multitasking
Differences between multi-threading and
multitasking
Differences between MultiTasking and
Multithreading
1.The basic difference between multitasking and multithreading is that
in multitasking, the system allows executing multiple programs and tasks
at the same time, whereas, in multithreading, the system executes
multiple threads of the same or different processes at the same time.
2.In multitasking CPU has to switch between multiple programs so that it
appears that multiple programs are running simultaneously. On other
hands, in multithreading CPU has to switch between multiple threads to
make it appear that all threads are running simultaneously.
3.Multitasking allocates separate memory and resources for each
process/program whereas, in multithreading threads belonging to the
same process shares the same memory and resources as that of the
process.
Multitasking and Multithreading
Examples of multitasking and multithreading
• MultiTasking is sharing of computer resources among number of
processes or execution of different processes at the same time
like working on MSOffice while VLC player is running whereas
• If Thread B waits for Thread A to produce data, it will waste many CPU
cycles.
• But if threads A and B communicate with each other when they have
completed their tasks, they do not have to wait and check each
other’s status every time.
How to achieve Inter-thread communication ?
• wait()
• notify()
• notifyAll()
Method Description
The wait() method releases the lock. The sleep() method doesn't release the lock.
It should be notified by notify() or notifyAll() After the specified amount of time, sleep is
methods completed.
Daemon Thread
• Daemon thread in Java are those thread which runs in background and mostly created by
JVM for performing background task like Garbage collection.
• Daemon threads are threads that run intermittently in the background as long as other
non-daemon threads are running.
• Daemon threads are service providers for user threads running in the same process.
Thread Groups
• ThreadGroup creates a group of threads. It offers a convenient way to
manage groups of threads as a unit. This is particularly valuable in
situation in which you want to suspend and resume a number of
related threads.
• The thread group form a tree in which every thread group except the
initial thread group has a parent.
• A thread is allowed to access information about its own thread group
but not to access information about its thread group’s parent thread
group or any other thread group.
Thread Group
Constructor Description