Created
November 10, 2015 14:29
-
-
Save arahansa/5a0a276007d716310eac to your computer and use it in GitHub Desktop.
Executor 알기- http://javacan.tistory.com/124
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArahanThreadExecutor { | |
public static void main(String[] args) throws InterruptedException, ExecutionException { | |
ExecutorService executor = Executors.newFixedThreadPool(1); | |
Future taskTwo = executor.submit(new ArahansaThread("TaskTwo", 4)); | |
System.out.println("waiting...시작 !?"); | |
//============================ | |
if(taskTwo.get() == null) { | |
System.out.println(" 태스크가 종료되었다. "); | |
} else { | |
// if it doesn't finished, cancel it | |
taskTwo.cancel(true); | |
} | |
System.out.println("여기 위로==== 블락... "); | |
executor.shutdown(); | |
} | |
} | |
class ArahansaThread implements Runnable{ | |
private String myName; | |
private int count; | |
ArahansaThread(String name, int newcount) { | |
this.myName = name; | |
this.count = newcount; | |
} | |
@Override | |
public void run() { | |
// TODO Auto-generated method stub | |
int sum = 0; | |
for (int i = 1; i <= this.count; i++) { | |
sum = sum + i; | |
try { | |
System.out.println(myName+" Thread :: "+ i); | |
TimeUnit.SECONDS.sleep(1); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
System.out.println(myName + "이 종료됨"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment