Created
June 17, 2015 13:01
-
-
Save enesakar/1cd7cfffc80c258fa3f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 static void main(String[] args) throws ExecutionException, InterruptedException { | |
| final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); | |
| final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); | |
| IExecutorService exec = instance1.getExecutorService("exec"); | |
| List<Future> flist = new ArrayList<Future>(); | |
| for (int i = 0; i < 10; i++) { | |
| Future<Object> future = exec.submitToKeyOwner(new TaskCallable(i), i); | |
| flist.add(future); | |
| } | |
| exec.shutdown(); | |
| exec.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); | |
| for (Future future : flist) { | |
| System.out.println(future.get()); | |
| } | |
| } | |
| static class TaskCallable implements Callable, Serializable { | |
| int x; | |
| TaskCallable(int x) { | |
| this.x = x; | |
| } | |
| @Override | |
| public Object call() throws Exception { | |
| System.out.println("started:"+x); | |
| Thread.sleep(1000); | |
| return x; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment