方法一:
package com.abin.lee.thread;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class ThreadSync{
public static List<Object> ThreadSync(final String message) throws InterruptedException{
final List<Object> list=new LinkedList<Object>();
Thread thread=new Thread(){
public void run(){
if(message.equals("one")){
list.add(0, message);
}
}
};
thread.start();
thread.join();
return list;
}
public static void main(String[] args) throws InterruptedException {
List<Object> list=ThreadSync("one1");
System.out.println("size="+list.size());
for(Iterator it=list.iterator();it.hasNext();){
Object obj=(Object)it.next();
System.out.println("obj="+obj);
}
}
}
方法二: