Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Init.java
- package thread;
- public class Init {
- public static void main(String[] args) {
- new ThreadDemo("thread1").start();
- new ThreadDemo("thread2").start();
- }
- }
- // ThreadDemo.java
- package thread;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class ThreadDemo extends Thread {
- String threadName;
- ThreadDemo(String threadName) {
- this.threadName = threadName;
- }
- public void run() {
- try {
- for (int x = 0; x < 5; x++) {
- System.out.println(threadName + " " + x);
- Thread.sleep(5000); // 5 sec
- }
- } catch (Exception ex) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment