Results 1 to 4 of 4

Thread: What is threading in JAVA?

  1. #1
    Join Date
    Feb 2009
    Posts
    2

    What is threading in JAVA?

    Hi,

    What is threading in JAVA?

  2. #2
    Join Date
    May 2008
    Posts
    44

    Re: What is threading in JAVA?

    a thread is a program's path of execution. Most programs written today run as a single thread, causing problems when multiple events or actions need to occur at the same time. Let's say, for example, a program is not capable of drawing pictures while reading keystrokes. The program must give its full attention to the keyboard input lacking the ability to handle more than one event at a time. The ideal solution to this problem is the seamless execution of two or more sections of a program at the same time. Threads allows us to do this.

    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, however, it is not the same as starting a program twice and saying that there are multiple lines of a program being executed at the same time. In this case, the operating system is treating the programs as two separate and distinct processes. Under Unix, forking a process creates a child process with a different address space for both code and data. However, fork() creates a lot of overhead for the operating system, making it a very CPU-intensive operation. By starting a thread instead, an efficient path of execution is created while still sharing the original data area from the parent. The idea of sharing the data area is very beneficial

  3. #3
    Join Date
    May 2008
    Posts
    35

    Re: What is threading in JAVA?

    Threads
    A thread is in process in execution within a program. Within a program each thread defines a separate path of execution.
    Creation of a thread
    A thread can be created in two ways
    a) By implementing the Runnable interface. The Runnable interface consists of only one method - the run method. The run method has a prototype of
    Code:
        public void run();
    b) By extending the class Thread.

    Execution of a thread
    To execute a thread, the thread is first created and then the start() method is invoked on the thread. Eventually the thread would execute and the run method would be invoked. The example below illustrates the two methods of thread creation. You should note that the run method should not be invoked directly.


    Code:
        public class ThreadExample extends Thread {
           public void run() {
              System.out.println("Thread started");
           }
           public static void main(String args[]) {
              ThreadExample t = new ThreadExample();
              t.start();
           }
        }
    Example - Creation of Thread by extending the
    Thread class.


    When the run method ends, the thread is supposed to "die". The next example shows the creation of thread by implementing the Runnable interface.


    Code:
        public class ThreadExample2 implements Runnable {
           public void run() {
           .../* Code which gets executed when 
                 thread gets executed. */
           }
           public static void main(String args[]) {
              ThreadExample2 Tt = new ThreadExample2();
              Thread t = new Thread(Tt);
              t.start();
           }
        }
    
        Example - Creating thread by implementing Runnable

  4. #4
    Join Date
    May 2008
    Posts
    115

    Re: What is threading in JAVA?

    Please go through this tutorial

    http://www.freejavaguide.com/java-threads-tutorial.pdf

    I hope this helps you!

Similar Threads

  1. Threading in c# .net
    By Athreya in forum Software Development
    Replies: 3
    Last Post: 12-01-2011, 03:29 PM
  2. What is Hyper threading
    By Ameeryan in forum Overclocking & Computer Modification
    Replies: 2
    Last Post: 06-10-2009, 04:03 PM
  3. What is Threading in C# Programming ?
    By HAKAN in forum Software Development
    Replies: 2
    Last Post: 31-03-2009, 11:18 AM
  4. VB.NET threading question
    By AmolP in forum Software Development
    Replies: 3
    Last Post: 14-02-2009, 06:03 PM
  5. Threading Unleashed
    By Cool_Rahul in forum Software Development
    Replies: 0
    Last Post: 19-12-2008, 01:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,909,884.24105 seconds with 17 queries