Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Who can tell me how this program runs?

Thread view: 
Jack Dowson - 02 May 2007 18:15 GMT
Hello Everybody:

Here is a program written to learn the multithread character of java!
class NewThread4 extends Thread{
    NewThread4(String name){
        super(name);
        }
    public void run(){
        for(int count = 10,row = 0; row<10 ; row++){
            for(int i = 0; i< count ; i++)
                System.out.print('*');
            System.out.println();
                }
        System.out.println(currentThread().getName() + " is over");
            }
        }
class ThreadDemo4{
    public static void main(String[] args){
        NewThread4 thd = new NewThread4("new Thread");
        thd.start();
        for(int i =0 ; i<10; i++){
            System.out.println(Thread.currentThread().getName()+ " is running");
            }
        System.out.println(Thread.currentThread().getName() + " is over!");
        }
    }

The output is out of my anticipation!
I don't know how it works?

Any reply will be greatly appreciated!
Daniel Pitts - 03 May 2007 02:35 GMT
> Hello Everybody:
>
[quoted text clipped - 27 lines]
>
> Any reply will be greatly appreciated!

Well, I'm not sure what you're seeing, but the point is that once you
call thd.start(), a new thread is spawned, and the run method of your
NewThread4 is executed in that other thread.

What this means is that the code in your run() method can run at the
same time as the code in your main method.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.