Simple thread program 1
/* programming for thread using Runnable Interface*/
package threads;
class SimpleThread implements Runnable
{
public void run()
{
System.out.println("Thread implementing by runnable interface... ");
}
}
class Main
{
public static void main(String[] args)
{
SimpleThread st=new SimpleThread();
Thread t=new Thread(st);
t.start();
// t.start(); generates exception becuse previous thread is in runing state.
}
}
Output
Thread implementing runnable interface...
Simple thread program 2
/* programming for thread using Thread Class*/
package threads;
class ThreadClass extends Thread
{
public void run()
{
System.out.println("Thread inheriting process runs...");
}
}
class Code
{
public static void main(String[] args)
{
ThreadClass tc=new ThreadClass();
tc.start();
}
}
Output
Thread inheriting process runs...
/* programming for thread using Runnable Interface*/
package threads;
class SimpleThread implements Runnable
{
public void run()
{
System.out.println("Thread implementing by runnable interface... ");
}
}
class Main
{
public static void main(String[] args)
{
SimpleThread st=new SimpleThread();
Thread t=new Thread(st);
t.start();
// t.start(); generates exception becuse previous thread is in runing state.
}
}
Output
Thread implementing runnable interface...
Simple thread program 2
/* programming for thread using Thread Class*/
package threads;
class ThreadClass extends Thread
{
public void run()
{
System.out.println("Thread inheriting process runs...");
}
}
class Code
{
public static void main(String[] args)
{
ThreadClass tc=new ThreadClass();
tc.start();
}
}
Output
Thread inheriting process runs...
No comments:
Post a Comment