ループがありますが、重すぎるので複数のスレッドで同じものを共有したいのですが、その方法がわかりません。
while(!labyrinth.exit(bob3) && !labyrinth.exit(bob2)) {
Collection<Room> accessibleRooms = labyrinth.accessibleRooms(bob3);
if (bob3.canMove()) {
destination = bob3.makeChoice(accessibleRooms);
}
if (destination != bob3.getPosition()) {
destination.receive(bob3);
}
accessibleRooms = labyrinth.accessibleRooms(bob2);
if (bob2.canMove()) {
destination = bob2.makeChoice(accessibleRooms);
}
if (destination != bob2.getPosition()) {
destination.receive(bob2);
}
}
ご覧のとおり、このループには 2 つの同一の操作があるため、それぞれに異なるスレッドを使用させることができます。