Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RunnableDemo implements Runnable {
- private Thread t;
- private String threadName;
- RunnableDemo( String name) {
- threadName = name;
- }
- public void run() {
- int x=1;
- int sum=0;
- for(int y=0;y<10;y++)
- {
- sum+=y;
- }
- x+=sum;
- System.out.println("Thread : "+threadName+" - value : "+x);
- }
- public void start () {
- if (t == null) {
- t = new Thread (this, threadName);
- t.start ();
- }
- }
- }
- public class TestThread {
- public static void main(String args[]) {
- RunnableDemo A = new RunnableDemo( "A");
- A.start();
- RunnableDemo B = new RunnableDemo( "B");
- B.start();
- RunnableDemo C = new RunnableDemo( "C");
- C.start();
- }
- }
Add Comment
Please, Sign In to add comment