Monday, June 30, 2014

Runnable

package Algorithm;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class ExtendImpl implements Runnable {

@Override
public void run() {
System.out.println("3");

}

@Test
public void Start() {
List<Runnable> list = new ArrayList<Runnable>();
Runnable impl1 = new ExtendImpl();
Runnable impl11 = new ExtendImpl();
Runnable impl111 = new ExtendImpl();
Runnable impl1111 = new ExtendImpl();
Runnable impl2 = new ExtendImpl1();
Runnable impl3 = new ExtendImpl2();
list.add(impl1);
list.add(impl2);
list.add(impl3);
list.add(impl11);
list.add(impl111);
list.add(impl1111);
for (Runnable r : list) {
r.run();
}
}
}

class ExtendImpl1 implements Runnable {
// Singleton if it uses the same singleton object
//can be problem when both uses it

@Override
public void run() {
System.out.println("1");
}

}

class ExtendImpl2 implements Runnable {
// Singleton if it uses the same singleton object

@Override
public void run() {
System.out.println("2");
}

}
class Singleton{
private String name ;
}

No comments:

Post a Comment