Skip to content

Instantly share code, notes, and snippets.

@hendrikebbers
Created September 27, 2016 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendrikebbers/c249f88e21600008bcb345467632bd8d to your computer and use it in GitHub Desktop.
Save hendrikebbers/c249f88e21600008bcb345467632bd8d to your computer and use it in GitHub Desktop.
final List<String> baseList = new ArrayList<>();
final List<String> unmodifiableList = Collections.unmodifiableList(baseList);
Executors.newSingleThreadExecutor().execute(() -> {
while(true) {
baseList.add(UUID.randomUUID().toString());
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
for(String s : unmodifiableList) {
System.out.println("Val: " + s);
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment