Created
May 30, 2017 21:17
-
-
Save gushernobindsme/a57f11623dfcf6a14b9399b1b0dd336a to your computer and use it in GitHub Desktop.
Callableインタフェースサンプル実装
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
import java.util.Date; | |
import java.util.concurrent.*; | |
/** | |
* Created by eratakumi on 2017/05/31. | |
*/ | |
public class CallableSample { | |
public static void main(String[] args){ | |
ExecutorService ex = Executors.newSingleThreadExecutor(); | |
System.out.println("Start : " + new Date()); | |
Future<Date> future = ex.submit(new ThreadA()); | |
try { | |
Date date = future.get(); | |
System.out.println("End : " + date); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} catch (ExecutionException e) { | |
e.printStackTrace(); | |
} | |
ex.shutdown(); | |
} | |
} | |
class ThreadA implements Callable<Date> { | |
public Date call() throws Exception { | |
Thread.sleep(3000); | |
return new Date(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment