aspose file tools*
The moose likes Threads and Synchronization and the fly likes Confusion between Single Thread and Multi thread. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Confusion between Single Thread and Multi thread." Watch "Confusion between Single Thread and Multi thread." New topic
Author

Confusion between Single Thread and Multi thread.

lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
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?

Thanks.
Lokesh Kumar Pattajoshi
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

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


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41519
    
  53
You may want to work through the chapter on concurrency in the Sun Java Tutorial: http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html

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.


Ping & DNS - my free Android networking tools app
 
Don't get me started about those stupid light bulbs.
 
subject: Confusion between Single Thread and Multi thread.