Skip to content

Instantly share code, notes, and snippets.

@danielshaya
Last active March 16, 2018 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielshaya/ddd27fc5d40d638504fcddb331985537 to your computer and use it in GitHub Desktop.
Save danielshaya/ddd27fc5d40d638504fcddb331985537 to your computer and use it in GitHub Desktop.
Allocation free logging
package test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class GCLogger {
private final static Logger LOGGER = LoggerFactory.getLogger(GCLogger.class);
public static void main(String[] args) throws InterruptedException {
List<String> list = IntStream.range(0,(int)1e6)
.mapToObj(i->"" + i)
.collect(Collectors.toList());
//Log 1 million lines in a loop sleeping 1 second between each iteration of the loop
//to allow time to run Flight Recorder.
for (int i = 0; i < 1000; i++) {
list.forEach(s->LOGGER.info("Logging [{}]", s));
Thread.sleep(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment