Skip to main content

Thread in java


Multitasking:

Executing several task simultaneously is called multitasking

Process-based multitasking:- Executing several task simultaneously where each task is a separate independent process such type of multitasking is called process based Multitasking. 
  Example:-While typing a program in the editor we can listen MP3 audio songs. At the same time we download a file from the net.       all these task are executing simultaneously and each task is a separate independent program. hence it is process based multitasking. It is best suitable at operating system level. 

Thread-based multitasking:- Executing several task simultaneously where each task is a separate independent part of the same program is called Thread-based multitasking. and every independent part is called a thread. This type of multitasking is best suitable at programmatic level.


Multithreading:


Executing several thread simultaneously where each thread is a separate independent part of the same program is called multithreading. Java language provides inbuilt support for multithreading by defining a rich library, classes and interfaces like Thread, ThreadGroup, Runnable etc. 
Examples:The main important application area of multithreading are video games implementation, animation development, multimedia graphics etc.


Advantage of Multithreading: 
The main advantage of multithreading is reduces response time and improves performance of the system

When compared with C++ what is the advantage in java with respect to  Multithreading :

Java language provides inbuilt support for multithreading by defining a reach library, classes and interfaces like Thread, ThreadGroup, Runnable etc. But in c++ there is no inbuilt support for multithreading

How Many ways we can define a Thread




We can define a Thread in the following two ways:
1.      by extending Thread class or
2.      by implementing Runnable interface.
Among the two ways of defining a thread implementing Runnable mechanism is always recommended. In the first approach as our Thread class already extending Thread there is no chance of extending any other. Hence, we missing the key benefit of oops(inheritance properties).




 

Comments

Popular posts from this blog

Yahoo! Calendar "Add Event" Seed URL Parameters

I can't seem to find any official documentation on this, so here are my notes. Some information gathered from  http://richmarr.wordpress.com/tag/calendar/ Other information gathered through trial and error, and close examination of the "Add Event" form on Yahoo!'s site. Yahoo! Calendar URL Parameters Parameter Required Example Value Notes v Required 60 Must be  60 . Possibly a version number? TITLE Required Event title Line feeds will appear in the confirmation screen, but will not be saved. May not contain HTML. ST Required 20090514T180000Z Event start time in UTC. Will be converted to the user's time zone. 20090514T180000 Event start time in user's local time 20090514 Event start time for an all day event. DUR value is ignored if this form is used. DUR 0200 Duration of the event. Format is HHMM, zero-padded. MM may range up to 99, and is converted into hours appropriately. HH values over 24 hours appear to be modulated by 24. Durations t...

What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?

The difference from the Java API Specifications is as follows. For  ClassNotFoundException : Thrown when an application tries to load in a class through its string name using: The  forName  method in class  Class . The  findSystemClass  method in class  ClassLoader . The  loadClass  method in class  ClassLoader . but no definition for the class with the specified name could be found. This exception also occurs when you have two class loaders and if a ClassLoader tries to access a class which is loaded by another classloader in Java. You must be wondering that what actually is classloader in Java.  Java ClassLoader  is a part of Java Runtime Environment that dynamically loads Java classes in JVM(Java Virtual Machine). The Java Runtime System does not need to know about files and files system because of classloaders. For  NoClassDefFoundError : Thrown if the Java Virtual Machine or a  ClassLoader ...