Results 1 to 9 of 9

Thread: Thread Threat

  1. #1
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Thumbs up Thread Threat

    what is the basic concept of thread ?I have read E.Balagurusamy and found threads running and exits according to priority but in case we have more threads and all having same priority than what would happen?Do tell me role of main method and execution terms of main method in threads?

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default Re: Thread Threat

    Hi. Java works with thread through native OS functions. Just read about how to realization this functions in special OS.
    Regard.

    PS What is mean Balagurusamy? :)
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Default Re: Thread Threat

    Quote Originally Posted by Petr View Post
    Hi. Java works with thread through native OS functions. Just read about how to realization this functions in special OS.
    Regard.

    PS What is mean Balagurusamy? :)
    Balagurusamy is a well known Indian author of Java .He wrote several Standard books in java .I have read that one last night .

  4. #4
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Default Re: Thread Threat

    give me some real world examples of threads utility .

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Thread Threat

    Reading data from the internet while responding to a user's requests on a GUI

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Thread Threat

    Riffing off Norm's post, threads are used by most every web server.
    One thread per request coming in (up to some thread limit).

  7. #7
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Default Re: Thread Threat

    sometimes i have seen we dint even inherit thread class nor interface runnable
    just by this statement ,programme runs
    Thread th =new thread();
    i dint understand why this happens?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Thread Threat

    Java Code:
    Thread th =new thread();
    What is the code in the thread class? Does it extend the Thread class? Remember java is case sensitive, so I'm talking about 2 different classes.

  9. #9
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Thread Threat

    I think thread() class is coded by programmer else that is wrong. Every thing is object in java. implementation is wrong but you can make smthg like that
    ex:
    public class myThread extends Thread{

    public myThread(){

    super ();

    }

    } // by this way you can add some other methods in Thread class and improve the class.

    I will simply explain thread in java.

    Thread is kind of process that runs the program.

    First difference of process and thread is important

    -process is a thread as well but you can not use process in process.
    -You can use threads in process.

    You can call process as main thread. In C that is a little different. (In C you use fork() to create thread .....)

    DataStructure are like tree;
    Process is the root;
    Threads are child or node;

    I can not explain structure of thread You can look in google or book;

    Second : In java when you run a program , process begins;
    In Process you can create threads that can make some independant work

    Simple example from this web site:> When you are writing reply you can see that Auto-Saved. Just like MS Word when you are writing in word program it automaticly saves content of word page. That means there are at least 2 thread (There are more than 2 thread) 1 thread handles writing second thread saves content when you are writing.
    1 thread only manages 1 job at the same time. You can not use 1 thread to do 2 works in sample period of time so you create second thread to handle that issue.

    ----------------------------------------END OF THREAD PURPOSE------------------------

    Thread th=new Thread();
    // your quesiton:> Thread is class you can get instance of Thread class but you have to make some modifications;
    Ex:

    Thread th=new Thread(){@Override public void run(){ System.out.println("HI");// implement some code for thread will deal}};
    th.start();
    System.out.println("HELLO");
    If you write this code to somewhere in method It will print HI and at the same time your program handles other jobs.


    I will mention about instance; // Just think that when you get instance of class (new Thread()), you creates a special memory for that class (Classes have Fields(int a,String b,.....) ,METHODS,MEMBERS..... as you know); For example: if you do not get instance, you can not use that classes' attributes(Fields); I will not explain static,dynamic variables

    Not every class can be got instance by user; //some class types : abstract class, Enum , interface, // you have to read them
    but all public classes can be got instance by user. //Even if they have private constructors .... I will just skip this explanation
    //my thoughts
    At last main class :>> If you know about nested class, main is nested class and anonymous class type.
    public static void main(String [] args) // First I will explain main properties.
    First it has to be public to access
    Second it has to be static because static variables or classes are created in runtime. //I do not know in java but static variables can be kept to cache for improve performance
    static variables can be accessed from every where // GLOBAL Variables
    Third if you write a programing language you need a specific class that you will need when runing program //Like in C, main is special class.

    String []args // if your program needs input from outside you can use it
    main thread is a main process of java --> As I said in above, Process is main thread. Root of java threads

    // For more information you search JVM , JIT , .....

Similar Threads

  1. Main Thread not waiting for grand child thread to finish
    By prashanthn in forum Threads and Synchronization
    Replies: 3
    Last Post: 06-07-2011, 09:26 AM
  2. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 05:37 PM
  3. Trigger main thread method from secondary thread?
    By DigitalMan in forum Threads and Synchronization
    Replies: 8
    Last Post: 01-26-2010, 02:13 AM
  4. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Tags for this Thread

Posting Permissions

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