Last active
March 16, 2018 08:15
-
-
Save danielshaya/ddd27fc5d40d638504fcddb331985537 to your computer and use it in GitHub Desktop.
Allocation free logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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