HI,
Can any body help me in java threading.What is the Difference between single thread and multi thread?is it possible to access a resources simultaneously in multi threaded environment if yes then will it not cause deadlock and if it is causing deadlock then what is the advantage of multi thread?
What is the Difference between single thread and multi thread?
Simply put, single threded means you have only one thread which is running all the code in the application so, Multi-threaded has more than one thread involved and can be run concurrently (through time slicing). Actually if the system has only one core, at a time only one thread will be running (but the user will see as if all are running concurrently). But it has the advantage of letting multiple threads finish their work more efficiently (ex: if one thread need to wait for something say user input and other thread(s) can utilize the valuable resources like processor time etc..).
is it possible to access a resources simultaneously in multi threaded environment
Principally, yes.
if yes then will it not cause deadlock and if it is causing deadlock then what is the advantage of multi thread?
Obviously, deadlocks are to be avoided - that's part of the art of concurrent programming. But just because a resource is shared between threads does not mean that it will cause a deadlock. One needs to analyze carefully the possible flows of control, and determine how the shared resource should be protected in order to avoid both deadlocks and inconsistent state.