• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Thread, synchronized, wait(), notify, notifyall

could u plz explain what these concept means in a very short way....and give some example where it is possible to use...

why we have threads in programming????

what mean thread??

what mean synchronizd??

what mean locks, notify and notifyall..

1 Solution
That's no possible to summarize shortly. I suggest


> why we have threads in programming????

When you want/need to do more than one thing at the same time

> what mean thread??

a thread is single thread of execution

> what mean synchronizd??

means a block of code that is guaranteed to only be executed by a single thread at one time
other threads will wait until it is com[plete before executing

> what mean locks, notify and notifyall..

they are for controlling thread execution
when a thread can hold a lock on a object, and also notify other threads when locks are freed etc.

MaggieshahAuthor Commented:
what mean deadlock??
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

when thread A is waiting for a lock help be thread B
But thread B is also waiting on a lock held by thread A
so both qare stuck
My point of view:

>> why we have threads in programming????
Only for programs that must perform several tasks in parallel, but mostly
for programs that must control multiple external events.
By dividing a program in threads one part of the program may wait for something while
another part goes on with some processing.
Formerly we did such a thing by 'frequently looking if something happened' but
the more frequently you look the more computer time is wasted.
A good example is a program that continues some processing, but is still
controlled by some button(s), e.g. an abort button.

>> what mean thread??
A single stream of instructions performed. When it ends (or returns) it is dead.
When all threads of a program are dead, the program is dead.

>> what mean synchronizd??
Co-operation between 2 or more threads so that they don't damage common data.
Image 2 programmers editing the same file: one must wait for the other's save and exit.
When one or more threads 'wait' for actions of another thread to complete,
we call the operation synchronized.
The keyword 'synchonized' in JAVA automatically invokes waiting of other threads.

>> what mean locks, notify and notifyall..
A lock is a way to make threads wait; it can be a variable or such;
notify is an action to wake-up a waiting thread;
notifyAll is an action to wake-up all threads that may wait for something.

>> what mean deadlock??
As 'objects' described: 2 or more threads waiting for each other (eternally).
It should of course never happen.

> and give some example where it is possible to use
consider you are writing a client/server chat system. the server must be able to deal with more than one client at a time. The way of dealing with this in Java is by multithreading. a thread is a task, or process, that may run in parallel with other processes. simply a thread is a program's path of execution. Multithreaded applications deliver their potent power by running many threads concurrently within a single program. From a logical point of view, multithreading means multiple lines of a single program can be executed at the same time. so in my example, the multithreaded chat server waits for a connection, when a connection is made, a new thread will be created and then looks after that connection. The server then waits for another connection while the client threads are listening to each client's request concurrently.
Mayank SAssociate Director - Product EngineeringCommented:
>> why we have threads in programming????

Consider a case of a simple web-server like Yahoo or experts-exchange. There is a web-application running there which 100s of users are accessing. So the web-server process needs to handle all of these requests 'parallelly', hence in different threads simultaneously so that it doesn't make one user wait until it has entirely handled the other user.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now