aspose file tools*
The moose likes Threads and Synchronization and the fly likes Question on thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Question on thread" Watch "Question on thread" New topic
Author

Question on thread

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Hi,

Can someone explain me the different types of multithreading?

thanks,
sanjana
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

There isn't any particular set of "types of multithreading" that I'm aware of. The right answer would, I imagine, depend on what the instructor has taught you this quarter.


[Jess in Action][AskingGoodQuestions]
sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
One of my friend was interviewed on this topic and she couldn't answer it. I am just curious to know what it would be. I referred a couple of books on threads and they had no mention of it.
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
Implementing Runnable versus subclassing Thread maybe?

ms


ms<br />SCJP, SCJD
Jeff Walker
Ranch Hand

Joined: Apr 25, 2004
Posts: 116
Tough Computer Science type of question. Only related to Java because you can do concurrent programming in Java.
Here's my answer:

There are 4 main types of multithreading. They are:

1. Unrelated Multi-threaded programing.
It's tough to think of a decent industrial-strength example, but I suspect something like what servlets do would suffice. E.g. each servlet instance running in a separate thread servicing a different unrelated HTTP request. Threads never communicate and never share data of any kind. (Only if the session object is not used).

2. Related but Unsynchronized Multi-threaded programnming.
Threads are related, in that they work to solve a common overall problem, but do not touch each others data. E.g. Gaussian Elimination, or matrix multiplication, where multiple threads can operate on the same data structure and NEVER tred on each others toes, mainly because they never access the same exact data. (It's been awhile since i did GE or matrices, so, perhaps these aren't great examples?)

3. Mutually Exclusive Mutli-threaded programming.
Example: Any program that makes use of heavy use of synchronized code blocks or synchronized static methods, but doesn't care about the other threads and so there is no inter-thread communication going on. E.g. gui programs that must run the gui in a separate thread for immediate client response, while the model/business logic is performed in a separate daemon thread. Any program that uses daemon threads only, is a candidate.

4. Communicating Mutually Exclusive Mutli-threaded programming.
Example: Classic example is the Producer/Consumer program. Heavy use of synchronized code blocks as well as calls to wait() and notify(). JMS style messaging may be a decent example, if the messages are produced and consumed within the same application, but by different threads running within the same application. Each thread must communicate with the other threads by setting a flag somewhere to let the other threads know that a resource is available for access.

Jeff Walker
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on thread