Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Can I call a run method of thread class directly?

Yes, you can call the run method of a Thread Class Directly. But when you call ‘run’ method directly, it executes like a normal method execution.

Application.java
package com.sample.app;

public class Application {

private static Thread thread = new Thread() {
public void run() {
System.out.println("Hello World");
}
};

public static void main(String args[]) {
thread.run();
thread.run();
}
}

Output
Hello World
Hello World

You may like
Interview Questions
Programming Questions
Miscellaneous
Static and Dynamic class loading
Different ways to dynamically load a class
Class.forName vs ClassLoader.loadClass
How the jdbc driver is loaded?
Can I overload main method of a class?
Can I throw an exception from static block?
Does yield method releases the lock?


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Can I call a run method of thread class directly?

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×