Skip to content

Instantly share code, notes, and snippets.

@enesakar
Created June 17, 2015 13:01
Show Gist options
  • Select an option

  • Save enesakar/1cd7cfffc80c258fa3f8 to your computer and use it in GitHub Desktop.

Select an option

Save enesakar/1cd7cfffc80c258fa3f8 to your computer and use it in GitHub Desktop.
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