class XThread extends Thread {
XThread() {
}
XThread(String threadName) {
super(threadName); // Initialize thread.
//System.out.println(this);
start();
}
public void run() {
//Display info about this particular thread
System.out.println("Thread started.");
}
}
public class ThreadExample {
public static void main(String[] args) {
Thread thread1 = new Thread(new XThread(), "thread1");
//Start the thread
thread1.start();
while (true){
try {
//The sleep() method is invoked on the main thread to cause a one second delay.
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
}
//Display info about the main thread
System.out.println(Thread.currentThread());
System.out.println("Implement your function here.");
}
}
}
class CustomThread extends Thread {
CustomThread() {}
CustomThread(final String threadname) {
setName(threadname);
}
@Override
public void run() {
while (true) {
System.out.println(Thread.currentThread().getName() + " executed,waiting for 1s");
try {
Thread.sleep(1000); // 1000 = 1s , so for 15 minutes insert the value 1000*60*15
}
catch (final InterruptedException ie) {}
}
}
}
public class MainThread {
public static void main(final String... args) {
System.out.println("main thread triggered");
System.out.println("custom threads triggered");
new CustomThread("thread 1").start();
//new CustomThread("thread 2").run();
System.out.println("main thread ended");
}
}