diff options
Diffstat (limited to 'sem5/oop/m5/opg2/src')
-rw-r--r-- | sem5/oop/m5/opg2/src/Main.java | 10 | ||||
-rw-r--r-- | sem5/oop/m5/opg2/src/PrintThread.java | 20 |
2 files changed, 30 insertions, 0 deletions
diff --git a/sem5/oop/m5/opg2/src/Main.java b/sem5/oop/m5/opg2/src/Main.java new file mode 100644 index 0000000..26b95b3 --- /dev/null +++ b/sem5/oop/m5/opg2/src/Main.java @@ -0,0 +1,10 @@ + +public class Main { + + public static void main(String[] args) { + for(int i=0;i<args.length;i++) { + new PrintThread( args[i] ).start(); + } + } + +} diff --git a/sem5/oop/m5/opg2/src/PrintThread.java b/sem5/oop/m5/opg2/src/PrintThread.java new file mode 100644 index 0000000..50b8425 --- /dev/null +++ b/sem5/oop/m5/opg2/src/PrintThread.java @@ -0,0 +1,20 @@ +public class PrintThread extends Thread { + private int sleepTime; + + public PrintThread(String id ) + { + super(id); + sleepTime = (int) ( Math.random() * 5000 ); + System.out.println( "Name: " + getName() +" Sleep: " + sleepTime ); + } + + public void run() + { + try { + sleep( sleepTime ); + } + catch ( InterruptedException exception ) {} + System.out.println( "Thread " + getName() ); + } + +}
\ No newline at end of file |