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:com.basho.riak.presto.cli.CLI.java

public static void main(String[] args) throws Exception {

    Injector i = Guice.createInjector(Stage.PRODUCTION, //new JsonModule());
            new Module() {
                @Override//from  w  w  w  .  j  a  va2 s. com
                public void configure(Binder binder) {
                    jsonBinder(binder).addDeserializerBinding(Type.class)
                            .to(Deserializer.CLITypeDeserializer.class);
                    binder.bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class);
                    binder.bind(JsonCodecFactory.class).in(Scopes.SINGLETON);
                }
            });
    log.debug("%s", i.getTypeConverterBindings());

    if (args.length < 4) {
        usage();
        return;
    }

    String hostname = args[0];
    String port = args[1];
    String command = args[2];
    String schemaName = args[3];
    RiakConfig config = new RiakConfig(hostname, port);

    // Actual command implementations
    if (command.equals("list-tables") && args.length == 4) {
        new SchemaDef(i, config).listTables(schemaName);
    } else if (command.equals("setup-schema") && args.length == 4) {
        new SchemaDef(i, config).setupSchema(schemaName);

    } else if (args.length == 5) {
        String tableArg = args[4];
        if (command.equals("create-schema")) {
            CLI.log("This option is not currently supported.");
        } else if (command.equals("create-tabledef")) {
            new TableDef(i, config, schemaName, true).create(tableArg);
        } else if (command.equals("show-tabledef")) {
            new TableDef(i, config, schemaName, true).show(tableArg);
        } else if (command.equals("clear-tabledef")) {
            new TableDef(i, config, schemaName, true).clear(tableArg);
        } else if (command.equals("check-tabledef")) {
            new TableDef(i, config, schemaName, false).check(tableArg);
        }

    } else if (args[0].equals("plan")) {
        System.out.println(args[1]);

        String node = args[1];
        String cookie = "riak";
        if (args.length > 2) {
            cookie = args[2];
        }
        System.out.println("connecting to Riak node " + node + " with cookie=" + cookie);

        String self = "client@127.0.0.1";
        try {
            DirectConnection conn = new DirectConnection(self, cookie);
            conn.connect(node);
            //conn.pid();
            //conn.ping();
            Coverage coverage = new Coverage(conn);
            coverage.plan();
            List<SplitTask> splits = coverage.getSplits();

            System.out.println("print coverage plan==============");
            System.out.println(coverage.toString());

            for (SplitTask split : splits) {
                System.out.println("============printing split data at " + split.getHost() + "===============");

                split.fetchAllData(conn, "default", "foobartable");
            }
        } catch (java.io.IOException e) {
            System.err.println(e);
        }
    } else {
        usage();
    }
    // Mock a Wock and don't leave any trash!
    System.gc();
}

From source file:com.l2jserver.model.template.NPCTemplateConverter.java

public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException, JAXBException {
    controllers.put("L2Teleporter", TeleporterController.class);
    controllers.put("L2CastleTeleporter", TeleporterController.class);
    controllers.put("L2Npc", BaseNPCController.class);
    controllers.put("L2Monster", MonsterController.class);
    controllers.put("L2FlyMonster", MonsterController.class);
    Class.forName("com.mysql.jdbc.Driver");

    final File target = new File("generated/template/npc");

    System.out.println("Scaning legacy HTML files...");
    htmlScannedFiles = FileUtils.listFiles(L2J_HTML_FOLDER, new String[] { "html", "htm" }, true);

    final JAXBContext c = JAXBContext.newInstance(NPCTemplate.class, Teleports.class);

    final Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD);
    {//from  w  w w  .  j a va2 s.c  o m
        System.out.println("Converting teleport templates...");
        teleportation.teleport = CollectionFactory.newList();

        final Marshaller m = c.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        final PreparedStatement st = conn.prepareStatement("SELECT * FROM teleport");
        st.execute();
        final ResultSet rs = st.getResultSet();
        while (rs.next()) {
            final TeleportationTemplate template = new TeleportationTemplate();

            template.id = new TeleportationTemplateID(rs.getInt("id"), null);
            template.name = rs.getString("Description");
            TemplateCoordinate coord = new TemplateCoordinate();
            coord.x = rs.getInt("loc_x");
            coord.y = rs.getInt("loc_y");
            coord.z = rs.getInt("loc_z");
            template.point = coord;
            template.price = rs.getInt("price");
            template.item = rs.getInt("itemId");
            if (rs.getBoolean("fornoble")) {
                template.restrictions = new Restrictions();
                template.restrictions.restriction = Arrays.asList("NOBLE");
            }
            teleportation.teleport.add(template);
        }
        m.marshal(teleportation, getXMLSerializer(new FileOutputStream(new File(target, "../teleports.xml"))));
        // System.exit(0);
    }

    System.out.println("Generating template XML files...");
    // c.generateSchema(new SchemaOutputResolver() {
    // @Override
    // public Result createOutput(String namespaceUri,
    // String suggestedFileName) throws IOException {
    // // System.out.println(new File(target, suggestedFileName));
    // // return null;
    // return new StreamResult(new File(target, suggestedFileName));
    // }
    // });

    try {
        final Marshaller m = c.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        final PreparedStatement st = conn.prepareStatement(
                "SELECT npc.*, npcskills.level AS race " + "FROM npc " + "LEFT JOIN npcskills "
                        + "ON(npc.idTemplate = npcskills.npcid AND npcskills.skillid = ?)");
        st.setInt(1, 4416);
        st.execute();
        final ResultSet rs = st.getResultSet();
        while (rs.next()) {
            Object[] result = fillNPC(rs);
            NPCTemplate t = (NPCTemplate) result[0];
            String type = (String) result[1];

            String folder = createFolder(type);
            if (folder.isEmpty()) {
                m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "npc ../npc.xsd");
            } else {
                m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "npc ../../npc.xsd");
            }

            final File file = new File(target, "npc/" + folder + "/" + t.getID().getID()
                    + (t.getInfo().getName() != null ? "-" + camelCase(t.getInfo().getName().getValue()) : "")
                    + ".xml");
            file.getParentFile().mkdirs();
            templates.add(t);

            try {
                m.marshal(t, getXMLSerializer(new FileOutputStream(file)));
            } catch (MarshalException e) {
                System.err.println("Could not generate XML template file for "
                        + t.getInfo().getName().getValue() + " - " + t.getID());
                file.delete();
            }
        }

        System.out.println("Generated " + templates.size() + " templates");

        System.gc();
        System.out.println("Free: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().freeMemory()));
        System.out.println("Total: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory()));
        System.out.println("Used: " + FileUtils.byteCountToDisplaySize(
                Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
        System.out.println("Max: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory()));
    } finally {
        conn.close();
    }
}

From source file:Main.java

public static void limparMemoria() {
    System.gc();
    Runtime.getRuntime().gc();//ww  w .j  av a 2 s. c om

    Log.i("GC", "LIMPANDO MEMORIA ANDROID");
}

From source file:Main.java

public static void entirelyexit() {
    System.exit(0);
    System.gc();
}

From source file:Main.java

public static void killProcess() {
    android.os.Process.killProcess(android.os.Process.myPid());
    System.gc();
    System.runFinalization();
}

From source file:Main.java

public static void Exit(Activity context) {

    context.finish();
    System.gc();

}

From source file:Main.java

private static Options getBitmapOption(int paramInt) {
    System.gc();
    Options localOptions = new Options();
    localOptions.inPurgeable = true;//from ww w .j  a  v a2 s.c  o m
    localOptions.inSampleSize = paramInt;
    return localOptions;
}

From source file:Main.java

public static void systemGC() {
    System.gc();
}

From source file:Main.java

public static BitmapFactory.Options getBitmapOption(int inSampleSize) {
    System.gc();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;/*from   w  w w .j  ava2s . c o  m*/
    options.inSampleSize = inSampleSize;
    return options;
}

From source file:Main.java

private static void recycleBitmap(Bitmap paramBitmap) {
    paramBitmap.recycle();
    System.gc();
}