ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
How to create two different thread class inside a main function?
 Question Submitted By :: Deepika
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to create two different thread class inside a main function?
Answer
# 1
The main important property of threads for concurrent and 
parallel programming is the possibility for a thread to 
execute in parallel with the application's main thread or 
with other threads. When the start() method is invoked a 
new thread is run, but the process which called the start() 
method will continue executing its own thread. Par 
consequence, the process can call once again the start() 
method and run another thread and so on, creating and 
running different threads in parallel. For example, 
consider the following program,

class Thready { 
    public static void main( String args [] ) { 
        new MyThread("A").start(); 
        new MyThread("B").start(); 
    } 
} 
 
class MyThread extends Thread { 
    String message; 
 
    MyThread ( String message ) { 
        this.message = message; 
    } 
 
    public void run() { 
        while ( true )  
            System.out.print( message ); 
    } 
} 
In this program, the lines


        new MyThread("A").start(); 
        new MyThread("B").start(); 

of the main(String args []) function of the class Thready 
start two threads of the class MyThread which are run in 
parallel. The thread which is initialized with the message 
"A" is started first and the thread which is initialized 
with the message "B" is stared immediately after the first 
thread was started. But the threads will execute in 
parallel since they are infinite loops. Otherwise the first 
thread which only prints a message can terminate before the 
second thread is started and the parallelism of the two 
threads can not occur.
 
Is This Answer Correct ?    2 Yes 1 No
Lakshmi
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is the relationship between a method?s throws clause and the exceptions that can be thrown during the method?s execution?  2
What is run-time class and system class? what is their purpose?  1
Does 'true' and 'false' are keywords?  5
Explain method overloading and overriding?  6
What is casting?  3
Explain the difference between scrollbar and scrollpane?  1
What class is used to implement a Throwable array?  3
If you are reviewing the code of your team members, what points will you look at, assuming the performance of the application is not so great KPIT2
How to make class immutable  5
write java code to print second max number in the array Huawei9
static inner classes means..?  1
they asked class A{} class B{} class c{} all the three class saved as a single file,there is no main method in the file and anothe class M.java class m { psvm(String args[]) { // here the parent class can access } } DNS1
What is file class and what is its purpose?  1
What is hard code & soft code? Wipro4
How does Vector implement synchronization? Ness-Technologies2
Given: 11. public static void main(String[] args) { 12. Integer i = uew Integer(1) + new Integer(2); 13. switch(i) { 14. case 3: System.out.println(”three”); break; 15. default: System.out.println(”other”); break; 16. } 17. } ‘What is the result? 1 three 2 other 3 An exception is thrown at runtime. 4 Compilation fails because of an error on line 12.  3
wahts is mean by thread? HCL14
Why Java is not purely object oriented? Persistent21
if two references are having same hash codes,is that means those are refering to same object? CTS4
How are this() and super() used with constructors?  4
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com