Skip to content

Instantly share code, notes, and snippets.

@gushernobindsme
Created May 30, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gushernobindsme/a57f11623dfcf6a14b9399b1b0dd336a to your computer and use it in GitHub Desktop.
Save gushernobindsme/a57f11623dfcf6a14b9399b1b0dd336a to your computer and use it in GitHub Desktop.
Callableインタフェースサンプル実装
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