Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws Exception {
- List<String> urls = new ArrayList<>();
- urls.add("1");
- urls.add("2");
- urls.add("3");
- urls.add("4");
- urls.add("5");
- urls.add("6");
- urls.add("7");
- urls.add("8");
- urls.add("9");
- urls.add("10");
- urls.stream().map(url -> new Thread(() -> {
- while (true) {
- if (isCanBuy()) {
- Steam.buy(url, 1, 1d);
- break;
- }
- }
- })).peek(Thread::start).collect(Collectors.toList());
- }
- public static boolean isCanBuy() {
- boolean b = new Random().nextBoolean();
- return b;
- }
- static class Steam {
- public static synchronized void buy(String url, Integer count, Double price) {
- System.err.println("Buy:" + url);
- try {
- Thread.sleep(1_000L);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement