I am working in IIT-Kanpur as project associate on java technology.
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sharad_Singh
Posted On:   Wednesday, September 7, 2005 02:05 AM

How can we use more than one thread in a java program?

Re: I am working in IIT-Kanpur as project associate on java technology.

Posted By:   siva_k  
Posted On:   Friday, October 21, 2005 06:45 AM

You can Give Your Runnable instance to more than one Thread instance.
By this way you can create any number of Threads in your Java Program.

Re: I am working in IIT-Kanpur as project associate on java technology.

Posted By:   Jani_Kaarela  
Posted On:   Friday, September 9, 2005 07:07 AM

You should perhaps select the subject of your question more carefully - who cares who and what you are?! It doesn't describe the topic at hand at all!


Sheesh... The quality of these forums is... no, has gone done the drain! Sadly, the people running it don't seem to pay any attention - as long as the ad money pours in, I guess...

Re: I am working in IIT-Kanpur as project associate on java technology.

Posted By:   Anonymous  
Posted On:   Thursday, September 8, 2005 10:30 AM

Here is an example program to show how we can use more than one thread in a java program.


public class ThreadExample extends Thread{// this class is extending thread


public static void main(String args[]){

// this is a main thread

ThreadExample te = new ThreadExample();

te.threadDemo();

te.start();

te.runnableDemo();


}


// when we call start method of the above thread the run method will execute

public void run(){

System.out.println("Hello Sharad");


}


public void threadDemo(){

ThreadExample t = new ThreadExample();

t.start();


}




public void runnableDemo(){

//new thread through runnable

Runnable r = new Runnable(){

public void run(){


System.out.println("hi Sharad");



}

};


r.start(); // it will start new thread

}


}



For more details please refer to the following links

http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html

http://docs.rinet.ru/JWP/ch16.htm

http://www.javaprepare.com/notes/threads.html



you can also practice coding online at www.devsquare.com

Re: I am working in IIT-Kanpur as project associate on java technology.

Posted By:   WarnerJan_Veldhuis  
Posted On:   Wednesday, September 7, 2005 03:48 AM

Look here and here. Please stick with Visual Basic....

Re: I am working in IIT-Kanpur as project associate on java technology.

Posted By:   manu_kaushal  
Posted On:   Wednesday, September 7, 2005 03:36 AM

There are tons of documents available to show that.
Create your own thread by implementing Runnable interface or by extending the Thread class. You can have as many of them as you want. For synchronization see java docs.


And please don't mallign IIT name by asking such simple questions here.

About | Sitemap | Contact