Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.genuinevm.coolrom;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.IntStream;
- public class Test {
- public static void main(String[] args) {
- // The thread safe list of entities that can and should be run in parallel.
- List<Entity> entityList = new ArrayList<>();
- // Populate lists with entities.
- IntStream.range(0, 256).forEach(Entity::new);
- // Run the ticks like movement, path finding, deciding what to do next.
- entityList.stream().parallel().forEach(Entity::normalTicks);
- // These would be placing blocks, executing things that affect other mobs.
- entityList.stream().sequential().forEach(Entity::notThreadSafeTicks);
- }
- }
- class Entity {
- private final int id;
- public Entity(int id) {
- this.id = id;
- }
- public void normalTicks() {
- try {
- Thread.sleep(10);
- }
- catch (InterruptedException e) {}
- }
- public void notThreadSafeTicks() {
- try {
- Thread.sleep(10);
- }
- catch (InterruptedException e) {}
- }
- }
Advertisement