Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


neelam
Java thread
1 Answer(s)      3 years and 10 months ago
Posted in : Java Interview Questions


Can we have run() method directly without start() method in threads?

Advertisement
View Answers

October 19, 2010 at 12:24 PM


Hi,

Here is the answer of the question.

The start() method performs some other actions before calling the run() method. The start() method starts the execution of the new thread and calls the run() method. The start() method returns immediately and the new thread normally continues until the run() method returns.

If we call run() directly, no separate thread will be created and it is just like calling any other method of the class which will be executed in the same thread.

Here is the example:

public class MyThread extends Thread {
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("within run");
        }
    }

    public static void main(String[] args) {
        MyThread mt = new MyThread();
        MyThread mt1 = new MyThread();
        mt.start();
        mt1.run();

    }

}


Related Tutorials/Questions & Answers:
java Thread
java Thread  what is purpose of Thread
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Advertisements
Java thread
Java thread  What are the high-level thread states
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Java thread
Java thread  Why do threads block on I/O?   When a thread... and in that time some other thread which is not waiting for that IO gets a chance to execute.If any input is not available to the thread which got suspended for IO
Thread in java
Thread in java  which method will defined in thread class
Java thread
Java thread  What is the use of serializable
Java thread
Java thread  What method must be implemented by all threads
Java thread
Java thread  What is the difference between wait() and sleep method
Java thread
Java thread  Can we have run() method directly without start() method in threads
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link... in Java Programming Language. These are Java Main Thread and the Child Thread. The Below reference will provides you clear idea of java thread concept. http
Java thread state
Java thread state  what is Static binding
Thread - Java Beginners
the concept of thread, thread creation and use of threads in JAVA application?  Thread creation and use of threads in JAVA Java Resourcehttp://www.roseindia.net/java/thread/thread-creation.shtml
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
Java thread lock
Java thread lock  What happens when a thread cannot acquire a lock on an object
Java thread state
Java thread state  Difference between sleep and suspend
Java thread state
Java thread state  What is the difference between yielding and sleeping
Java Thread
Java Thread In this tutorial we will discuss about Java Thread. Java Thread : A thread is light weight java program.JVM permits you to have multiple threads for concurrent execution. Each thread has priority. You can also set
thread - Java Beginners
thread  can i asko for programs in thread method that will allow user to input two separate names  Hi friend, For more information on Thread visit to : http://www.roseindia.net/java/thread/index.shtml Thanks
Java Thread
Java Thread Tutorials In this tutorial we will learn java Threads in detail. The Java Thread class helps the programmer to develop the threaded application in Java. Thread is simple path of execution of a program. The Java Virtual Machine
Daemon thread - Java Beginners
information, visit the following link: http://www.roseindia.net/java/thread...Daemon thread  Hi, What is a daemon thread? Please provide me... thread which run in background. like garbadge collection thread. Thanks 
Java Thread - Java Beginners
and simple examples of "Multithreading". 1. http://www.roseindia.net/java/thread/index.shtml 2. http://www.roseindia.net/java/thread...Java Thread  hii i feel confusion in tread. i want to know about 1
JAVA THREAD - Java Beginners
JAVA THREAD  hii i wrote a pgm to print the numbers from 0 to 9 in 2...); } public void fgh(int i,int p) { int sum; new Thread(public void run... Thread { private static int sums; public static int getSums
Extending thread - Java Beginners
visit to : http://www.roseindia.net/java/thread/index.shtml Thanks...Extending thread  what is a thread & give me the programm of exeucte the thread   Hi friend, Thread : A thread is a lightweight
java thread program
java thread program  write a java program to find out all the current running thread in a java program   public class RunningThreads...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
java thread program
java thread program  write a java program to find out the current running thread in a java program   public class RunningThreads{ public...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism...:/www.roseindia.net/java/thread/index.shtml
Java :Thread getPriority Example
Java :Thread getPriority Example In this tutorial you will learn how to get thread priority in java thread. Thread getPriority() : Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority 
Java Sleep Thread
Java Thread sleep() is a static method. It sleeps the thread for the given time in milliseconds. It is used to delay the thread. It is used in Applet or GUI programming for animation Java Sleep Thread Example public class
Java :Thread setPriority Example
Java :Thread setPriority Example In this tutorial you will learn how to set thread priority in java thread. Thread setPriority() : Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority 
java thread - Java Beginners
Java Thread  What is thread in Java? and how can i write a Java thread program?Thanks in advance!!  Hi friend,import javax.swing.*;import...(a); } private JPanel canvas;}class Ball extends Thread { public Ball(JPanel
java thread - Java Beginners
java thread  PROJECT WORK: Create a application using thread to implement the application. The application should consist of the following classes... . AccountManager.java The AccountManager class demonstrates creation of Thread objects using
Thread Deadlocks - Java Tutorials
Thread Deadlock Detection in Java Thread deadlock relates to the multitasking... is possible. In other words, a situation where a thread is waiting for an object lock that holds by second thread, and this second thread is waiting for an object
Green Thread - Java Beginners
of Green Thread in java. Thanks in advance...  Hi friend Green threads... thread), but VM technology has advanced significantly since version 1.1 and any... the years. This is simple program of thread public class ThreadExample
Explain the concept of thread priorities in Java.
Explain the concept of thread priorities in Java.  Explain the concept of thread priorities in Java
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second
Java Thread : getState() Example
Java Thread : getState() Example This section explains how to get state of a thread  in java Thread. Thread  getState() : Suppose you want to know the state of the thread so for that Java Thread provides Thread.getState
Thread and Process - Java Beginners
Thread and Process  Dear Deepak Sir, What is the diffrence between Thread and Process.Give an example with explanation. Thnaks & Regards... space; a thread doesn't. Threads typically share the heap belonging to their parent
thread inside other thread - Java Beginners
thread inside other thread  Hello, can you help me please: I want to connect client and server that the client send three times msg1 and when he send msg2 he will connect with another server by create new thread that use
Java Thread Context
Thread Context       The Thread Context is required by the current thread from the group of threads to execute. In java this is achieved through the ThreadContext class
Thread - Java Beginners
Thread  Can i ask a thread method that will input two names using...()); } }; Thread appThread = new Thread() { public void run() { try...://www.roseindia.net/java/ Thanks
thread class - Java Beginners
thread class  Create 2 Thread classes.One Thread is Incrementor... value of cnt1 by 1 each time. The other thread is Decrementor which has variable... each time. - Incrementor thread increments value of cnt1 by one
Thread
Thread  What is multi-threading? Explain different states of a thread.   Java Multithreading Multithreading is a technique that allows... processor system. States of Thread: New state ? After the creations of Thread
Java Thread class
Java Thread Class is a piece of the program execution Java has... It is created by extending the Thread class or implementing Runnable interface Java Thread Class Example public class thread1 extends Thread { @Override
Java Thread : setDaemon() method
Java Thread : setDaemon() method In this section we are going to describe setDaemon() method with example in java thread. Daemon Thread  : In Java Thread, daemon threads are used to perform services for user threads. You can
Java Thread : toString() method
Java Thread : toString() method In this section we are going to describe toString() method with example in java thread. toString() method : If you want to display string representation of thread you can use thread.toString
 

 

 

DMCA.com