Results 1 to 4 of 4
  1. #1
    simorgh is offline Member
    Join Date
    Jan 2010
    Posts
    25
    Rep Power
    0

    Default advantage of using thread

    One of the usage of threads in network programming.

    Say we have an application for a company that has 70 persons that want to chat each other on LAN network.

    The chat program has code for send messages. if this program does'nt use thread,then the other persons must wait until the person that sends the message.It means if one person uses the program . Then other 69 persons must wait until that person finish sending.and there is not other way ,unless create 70 function for sending. Right?

    Is it good example for usage thread in network programming?May you suggest another examples?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    consider a web application, where a Servlet uses threads to handle each concurrent request .

    another example of where threads are good, consider you have many rows in a database, or perhaps a graphics application where rendering shapes in a scene, where there is a lot of data which individually do not depend on each other, and that you must read it, perform some kind of [the same] computation, and then update it. using threads in some cases can sometimes improve the throuput, by dividing the large workload over multiple threads, instead of a single thread with a very large for() loop. Where in modern systems where there are more than one CPU core, a Java thread typically can be executed on the other available hardware CPU core(s). This is something that is managed internally at a low level by the Java VM and the operating system, so how exactly it does that is difficult to determine.

  3. #3
    senorbum is offline Member
    Join Date
    Aug 2009
    Posts
    76
    Rep Power
    0

    Default

    Threads are generally useful when, as travishein said, data in one thread is not dependent with data in another thread. The more dependencies you have, the less and less efficient threads are. This can easily get to a point where multiple threads are less efficient than a single thread for a given task.

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    I find that every nontrivial application I write uses threads, and most of the trivial ones do as well. Once you get much beyond 'hello world', you will be using threads either implicitly (in any gui development) or explicitly (pretty much everything else).

Similar Threads

  1. What is advantage of interface in java?Plz help
    By Eyeinstyin in forum New To Java
    Replies: 13
    Last Post: 09-08-2011, 01:12 AM
  2. Trigger main thread method from secondary thread?
    By DigitalMan in forum Threads and Synchronization
    Replies: 8
    Last Post: 01-26-2010, 02:13 AM
  3. Advantage of Using Interface Over Class.
    By makpandian in forum New To Java
    Replies: 5
    Last Post: 06-08-2009, 11:58 AM
  4. Replies: 7
    Last Post: 09-16-2008, 06:20 PM
  5. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •