异步加载
- package eu.plumbr.test;
- public class HealMe {
- private static final int SIZE = (int) (Runtime.getRuntime().maxMemory() * 0.6);
- public static void main(String[] args) throws Exception {
- for (int i = 0; i < 1000; i++) {
- allocateMemory(i);
- }
- }
- private static void allocateMemory(int i) {
- try {
- {
- byte[] bytes = new byte[SIZE];
- System.out.println(bytes.length);
- }
- byte[] moreBytes = new byte[SIZE];
- System.out.println(moreBytes.length);
- System.out.println("I allocated memory successfully " + i);
- } catch (OutOfMemoryError e) {
- System.out.println("I failed to allocate memory " + i);
- }
- }
- }
在IT行业,碰到问题的第一个反应通常是——“你重启过没”——而这样做可能会适得其反,本文要讲述的就是这样的一个场景。
接下来要介绍的这个应用,它不仅不需要重启,而且毫不夸张地说,它能够自我治愈:刚开始运行的时候它可能会碰到些挫折,但会渐入佳境。
转自:itxxz.com
浙公网安备 33010602011771号