Example usage for java.lang System gc

List of usage examples for java.lang System gc

Introduction

In this page you can find the example usage for java.lang System gc.

Prototype

public static void gc() 

Source Link

Document

Runs the garbage collector in the Java Virtual Machine.

Usage

From source file:io.selendroid.server.handler.ForceGcExplicitly.java

@Override
public Response safeHandle(HttpRequest request) throws JSONException {
    SelendroidLogger.info("force GC explicitly");

    ServerInstrumentation instrumentation = ServerInstrumentation.getInstance();
    instrumentation.runOnMainSync(new Runnable() {
        @Override//from   w  w  w  . ja  v  a2 s  .  c o  m
        public void run() {
            System.gc();
        }
    });

    return new SelendroidResponse(getSessionId(request), "");
}

From source file:org.cybercat.automation.core.WeakReferenceThreadScope.java

@SuppressWarnings("rawtypes")
public Object get(String name, ObjectFactory objectFactory) {
    System.gc();
    Map<String, WeakReference<Object>> scope = threadScope.get();
    WeakReference<Object> wRef = scope.get(name);
    Object object;/*from w ww  . j  a  v a  2  s. c  om*/
    if (wRef == null || wRef.get() == null) {
        scope.remove(name);
        object = objectFactory.getObject();
        wRef = new WeakReference<Object>(object);
        scope.put(name, wRef);
    } else {
        object = wRef.get();
    }
    return object;
}

From source file:com.adaptris.transport.TestPpp.java

@After
public void tearDown() throws Exception {
    System.gc();
}

From source file:com.cloudera.oryx.app.serving.als.model.LoadTestALSModelFactory.java

public static ALSServingModel buildTestModel() {

    log.info("Building load test model...");

    System.gc();
    long startMemory = JVMUtils.getUsedMemory();

    ALSServingModel model = new ALSServingModel(FEATURES, true, LSH_SAMPLE_RATE, new TestALSRescorerProvider());
    AtomicLong totalEntries = new AtomicLong();

    int numCores = Runtime.getRuntime().availableProcessors();
    log.info("Adding {} users", USERS);
    AtomicInteger userCount = new AtomicInteger();
    ExecUtils.doInParallel(numCores, i -> {
        RandomGenerator random = RandomManager.getRandom(((long) i << 32) ^ System.nanoTime());
        PoissonDistribution itemPerUserDist = new PoissonDistribution(random, AVG_ITEMS_PER_USER,
                PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
        for (int user = userCount.getAndIncrement(); user < USERS; user = userCount.getAndIncrement()) {
            String userID = "U" + user;
            model.setUserVector(userID, VectorMath.randomVectorF(FEATURES, random));
            int itemsPerUser = itemPerUserDist.sample();
            totalEntries.addAndGet(itemsPerUser);
            Collection<String> knownIDs = new ArrayList<>(itemsPerUser);
            for (int item = 0; item < itemsPerUser; item++) {
                knownIDs.add("I" + random.nextInt(ITEMS));
            }/*from  w  w w .  ja v a  2 s  . c om*/
            model.addKnownItems(userID, knownIDs);
        }
    });

    log.info("Adding {} items", ITEMS);
    AtomicInteger itemCount = new AtomicInteger();
    ExecUtils.doInParallel(numCores, i -> {
        RandomGenerator random = RandomManager.getRandom(((long) i << 32) ^ System.nanoTime());
        for (int item = itemCount.getAndIncrement(); item < ITEMS; item = itemCount.getAndIncrement()) {
            model.setItemVector("I" + item, VectorMath.randomVectorF(FEATURES, random));
        }
    });

    System.gc();
    long endMemory = JVMUtils.getUsedMemory();

    log.info("Built model over {} users, {} items, {} features, {} entries, using {}MB", USERS, ITEMS, FEATURES,
            totalEntries, (endMemory - startMemory) / 1_000_000);
    log.info("Model: {}", model);
    return model;
}

From source file:MemoryUtils.java

public static void freeMemory() {
    System.gc();
    System.runFinalization();
}

From source file:com.dotosoft.dot4command.commands.CallTemplateCommand.java

@Override
public Processing onExecute(C context) throws Exception {
    Command<K, V, C> command = getCommand(context);
    if (command != null) {
        Command newTemp = (Command) command.clone();
        modifyKeyMap(newTemp);// w w  w .ja  v a2 s  .  c  o  m

        Processing result = newTemp.execute(context);
        newTemp = null;
        System.gc();
        if (isIgnoreExecuteResult()) {
            return Processing.FINISHED;
        }
        return result;
    }
    return Processing.FINISHED;
}

From source file:com.espertech.esper.regression.epl.TestPerf3StreamCoercion.java

public void setUp() {
    epService = EPServiceProviderManager.getDefaultProvider(SupportConfigFactory.getConfiguration());
    epService.initialize();//w w  w  .j ava2  s. c om
    listener = new SupportUpdateListener();
    System.gc();
}

From source file:net.sf.ehcache.AbstractCacheTest.java

/**
 * Force the VM to grow to its full size. This stops SoftReferences from being reclaimed in favour of
 * Heap growth. Only an issue when a VM is cold.
 *//*  w w  w .  ja  v a 2  s .  co  m*/
static public void forceVMGrowth() {
    allocateFiftyMegabytes();
    System.gc();
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
        //
    }
    System.gc();
}

From source file:probe.com.model.util.SwingToImageGenerator.java

private String generateEncodedImg(BufferedImage image) {
    String base64 = "";
    try {/*  w w  w  . ja v  a  2 s  .  c om*/
        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, 0);
        byte[] imageData = in.encode(image);
        base64 = Base64.encodeBase64String(imageData);
        base64 = "data:image/png;base64," + base64;
        System.gc();
    } catch (IOException exp) {
        System.err.println(exp.getLocalizedMessage());
    }
    return base64;
}

From source file:com.imagelake.android.myuploads.CreateMyUploadthumbnail.java

public String createThumb(int uid) {
    System.out.println("uid=" + uid);
    String img = "";
    List<Images> imlist = idi.getMyUpload(uid);
    if (!imlist.isEmpty()) {

        for (Images images : imlist) {
            if (images.getUser_user_id() == uid) {
                if (images.getImage_state_image_state_id() != 7) {

                    JSONObject jo = new JSONObject();
                    jo.put("img_id", images.getImages_id());
                    jo.put("title", images.getTitle());
                    jo.put("state", images.getImage_state_image_state_id());
                    jo.put("url", images.getImg_url());
                    ja.add(jo);//from w ww  .  ja  v a  2 s .  c o  m
                }
            }
        }
        if (!ja.isEmpty()) {
            img = "json=" + ja.toJSONString();
        } else {
            img = "msg=No item found.";
        }
    } else {
        img = "msg=No item found.";
    }
    System.gc();
    return img;
}