package kr.co.swh.lecture.opensource.thread; 

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.apache.log4j.Logger;


/**
 * <pre>
 * kr.co.swh.lecture.opensource.thread 
 * ExcutorExample.java
 *
 * 설명 :
 * </pre>
 * 
 * @since : 2020. 10. 11.
 * @author : tobby48
 * @version : v1.0
 */
public class ExcutorExample {

	private Logger log = Logger.getLogger(this.getClass());

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		ExecutorService executor = Executors.newFixedThreadPool(4);
		ExecutorService executor1 = Executors.newSingleThreadExecutor();
		
		executor1.execute(new ThreadRunner());
		executor1.submit(new ThreadRunner());
		
		Future<Message> result = executor1.submit(new ThreadRunnerCall());
		try {
			System.out.println(result.get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		List<ThreadRunnerCall> list = new ArrayList<ThreadRunnerCall>();
		list.add(new ThreadRunnerCall());
		list.add(new ThreadRunnerCall());
		list.add(new ThreadRunnerCall());
		list.add(new ThreadRunnerCall());
		try {
			List<Future<Message>> response = executor.invokeAll(list);
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
//		Thread t = new Thread(new ThreadRunner());
//		t.start();
//		
//		ThreadRunner1 t2 = new ThreadRunner1();
//		t2.start();
	}

}

class Message{
	private String name;
	private String user;
	public Message(String name, String user) {
		this.name = name;
		this.user = name;
	}
}
class ThreadRunnerCall implements Callable<Message>{

	@Override
	public Message call() throws Exception {
		// TODO Auto-generated method stub
		System.out.print(1);

//		return "정상처리되었습니다";
		return new Message("돌샘", "정상처리되었습니다");
	}

}

class ThreadRunner implements Runnable{

	@Override
	public void run() {
		// TODO Auto-generated method stub
		System.out.print(1);
	}
	
}
class ThreadRunner1 extends Thread {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		System.out.print(1);
	}
	
}

