Link to home
Start Free TrialLog in
Avatar of Maggieshah
Maggieshah

asked on

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..

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

That's no possible to summarize shortly. I suggest

http://java.sun.com/docs/books/tutorial/essential/threads/


> 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.

Avatar of Maggieshah
Maggieshah

ASKER

what mean deadlock??
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
http://mindprod.com/jgloss/deadlock.html
ASKER CERTIFIED SOLUTION
Avatar of sciuriware
sciuriware

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> 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.
>> 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.