Q261. What is
Multithreading and explain its application areas?
Ans. 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 reach library, classes and interfaces like Thread, ThreadGroup,
Runnable etc. The main important application area of multithreading are video games implementation, animation development, multimedia graphics etc.
Q262.What is advantage of Multithreading?
Ans. The main advantage of multithreading is reduces response time and improves performance of the system.
Q263. When compared with C++ what is the advantage in java with respect to Multithreading?
Ans.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.
Q264. In how many ways we can define a Thread? Among extending Thread and implementing Runnable which is recommended?
Ans. 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).
Q265. What is the difference between t.start() and t.run() method?
Ans. In the case of t.start() method, a new thread will be created which is responsible for the
execution of run() method.
But in the case of t.run() method no new thread will be created main thread executes
run() method just like a normal method call.
Q266. Explain about Thread Scheduler?
Ans. If multiple threads are waiting for getting the chance for executing then which thread will get chance first decided by Thread Scheduler. It is the part of JVM and its behavior is vendor dependent and we can’t expect exact output.Whenever the situation comes to multithreading the guarantee behavior is very- very low.
Q267. If we are not overriding run() method what will happened?
Ans.If we are not overriding run() method then Thread class run() method will executed which has empty implementation and hence we will not get any output.
Q268.Is overloading of run() method is possible?
Ans.Yes, we can overload run() method but Thread class start() method always invokes no-
argument run() method only. The other run() method we have to call explicitly then only will be executed.
Q269.Is it possible to override start() method?
Ans. Yes it is possible. But not recommended.
Q270.If we are overriding start() method then what will happen?
Ans. It we are overriding start() method then our own start() method will be executed just like a normal method call. In this case no new Thread will be created.
Ans. 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 reach library, classes and interfaces like Thread, ThreadGroup,
Runnable etc. The main important application area of multithreading are video games implementation, animation development, multimedia graphics etc.
Q262.What is advantage of Multithreading?
Ans. The main advantage of multithreading is reduces response time and improves performance of the system.
Q263. When compared with C++ what is the advantage in java with respect to Multithreading?
Ans.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.
Q264. In how many ways we can define a Thread? Among extending Thread and implementing Runnable which is recommended?
Ans. 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).
Q265. What is the difference between t.start() and t.run() method?
Ans. In the case of t.start() method, a new thread will be created which is responsible for the
execution of run() method.
But in the case of t.run() method no new thread will be created main thread executes
run() method just like a normal method call.
Q266. Explain about Thread Scheduler?
Ans. If multiple threads are waiting for getting the chance for executing then which thread will get chance first decided by Thread Scheduler. It is the part of JVM and its behavior is vendor dependent and we can’t expect exact output.Whenever the situation comes to multithreading the guarantee behavior is very- very low.
Q267. If we are not overriding run() method what will happened?
Ans.If we are not overriding run() method then Thread class run() method will executed which has empty implementation and hence we will not get any output.
Q268.Is overloading of run() method is possible?
Ans.Yes, we can overload run() method but Thread class start() method always invokes no-
argument run() method only. The other run() method we have to call explicitly then only will be executed.
Q269.Is it possible to override start() method?
Ans. Yes it is possible. But not recommended.
Q270.If we are overriding start() method then what will happen?
Ans. It we are overriding start() method then our own start() method will be executed just like a normal method call. In this case no new Thread will be created.
No comments:
Post a Comment