Created
October 14, 2019 07:51
-
-
Save cmonkey/08ed80852d1629a170cf638539af9112 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.LinkedBlockingQueue; | |
import java.util.concurrent.ThreadPoolExecutor; | |
import java.util.concurrent.TimeUnit; | |
import java.util.stream.IntStream; | |
public class HighCpu{ | |
private static BlockingQueue<String> messageStrings = new LinkedBlockingQueue<>(); | |
public void init(){ | |
ExecutorService executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, | |
new LinkedBlockingQueue<>()); | |
executorService.submit(new BatchLogRunnable()); | |
} | |
static class BatchLogRunnable implements Runnable{ | |
@Override | |
public void run(){ | |
while (true) { | |
try { | |
Thread.sleep(3L); | |
StringBuilder builder = new StringBuilder(); | |
builder.append(messageStrings.take()); | |
System.out.println(builder.toString()); | |
} catch (InterruptedException exx) { | |
System.out.println(exx); | |
} | |
} | |
} | |
} | |
public static void main (String [] args) { | |
HighCpu hightCpu = new HighCpu(); | |
hightCpu.init(); | |
IntStream.range(0, 90000000).forEach(i -> { | |
try{ | |
messageStrings.put("test "); | |
}catch(Exception e){ | |
System.out.println(e); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment