Languages-Java [3i Infotech Placement]: Sample Questions 36 - 37 of 141

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 36

Edit

Describe in Detail

Essay▾

What do you mean by multithreading?

Explanation

  • A type of execution model that allows multiple threads to exist within a process- they execute independently but share process resources.
  • Thread maintains information relevant to its execution (context) including priority schedule, exception handlers, set of CPU registers, and stack state in the address space of its hosting process.
  • Mostly used in game, animation etc.

Advantages:

  • Threads share memory area (saving memory) and context-switching between the threads takes less time than switching process.
  • Threads do not block the user- they are independent and allow multiple operations at same time.
  • Independent- do not affect other threads if exception occurs.

Question 37

Edit

Describe in Detail

Essay▾

How can two threads be made to communicate with each other?

Explanation

Understanding of Two Thread Process
  • Two threads can communicate with each other using the wait () and modify () , notify () methods.
  • Wait () tells the thread to wait until another threads calls notify () method.
  • Wait () causes the current thread to wait unit another thread notifies it of a condition change.
  • We use wait () in conjunction with notify () or notifyAll () to coordinate the activities of multiple threads using the same resources.
  • The notifyAll () method notifies all the threads waiting on the monitor by the current thread and wakes them up- one of the waiting threads than grabs the monitor and proceeds.

Developed by: