blob: 9bada3adc440855f70b0d6d6a6cc3080b2896927 [file] [log] [blame]
// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.examples.loop;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class UdpServer {
private static final String PREFIX = "RANDOM_DATA_PREFIX_";
public static void main(String[] args) throws Exception {
ExecutorService service = Executors.newWorkStealingPool(2);
Callable<Object> c =
new Callable<Object>() {
@Override
public Object call() throws Exception {
int counter = 0;
byte[] receiveData = new byte[1024];
while (true) {
// Mimic receiving data via socket. (A use of actual socket is IO blocking.)
receiveData = (PREFIX + counter++).getBytes();
}
}
};
Future<Object> f = service.submit(c);
try {
f.get(1, TimeUnit.NANOSECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException e) {
System.out.println(e);
} finally {
f.cancel(true);
service.shutdownNow();
}
}
}