List of usage examples for java.lang System gc
public static void gc()
From source file:web.diva.server.model.profileplot.ProfilePlotImgeGenerator.java
@SuppressWarnings("CallToPrintStackTrace") public String toPdfFile(File userFolder, String url) { try {/*from w ww.java2s .c om*/ BufferedImage pdfImage = image; DOMImplementation domImpl = new SVGDOMImplementation(); String svgNS = "http://www.w3.org/2000/svg"; SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null); SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument); svgGenerator.setSVGCanvasSize(new Dimension(pdfImage.getWidth(), pdfImage.getHeight())); svgGenerator.setPaint(Color.WHITE); svgGenerator.drawImage(pdfImage, 0, 0, null); File pdfFile = new File(userFolder, dataset.getName() + "_Profile_Plot" + ".pdf"); if (!pdfFile.exists()) { pdfFile.createNewFile(); } else { pdfFile.delete(); pdfFile.createNewFile(); } // write the svg file File svgFile = new File(pdfFile.getAbsolutePath() + ".temp"); OutputStream outputStream = new FileOutputStream(svgFile); BufferedOutputStream bos = new BufferedOutputStream(outputStream); Writer out = new OutputStreamWriter(bos, "UTF-8"); svgGenerator.stream(out, true /* use css */); outputStream.flush(); outputStream.close(); bos.close(); System.gc(); String svgURI = svgFile.toURI().toString(); TranscoderInput svgInputFile = new TranscoderInput(svgURI); OutputStream outstream = new FileOutputStream(pdfFile); bos = new BufferedOutputStream(outstream); TranscoderOutput output = new TranscoderOutput(bos); Transcoder pdfTranscoder = new PDFTranscoder(); pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, 0.084666f); pdfTranscoder.transcode(svgInputFile, output); outstream.flush(); outstream.close(); bos.close(); System.gc(); return url + userFolder.getName() + "/" + pdfFile.getName(); } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:edu.iu.daal_qr.QRDaalCollectiveMapper.java
protected void mapCollective(KeyValReader reader, Context context) throws IOException, InterruptedException { long startTime = System.currentTimeMillis(); List<String> trainingDataFiles = new LinkedList<String>(); //splitting files between mapper while (reader.nextKeyValue()) { String key = reader.getCurrentKey(); String value = reader.getCurrentValue(); LOG.info("Key: " + key + ", Value: " + value); System.out.println("file name : " + value); trainingDataFiles.add(value);/*from www. ja v a2 s. co m*/ } Configuration conf = context.getConfiguration(); Path pointFilePath = new Path(trainingDataFiles.get(0)); System.out.println("path = " + pointFilePath.getName()); FileSystem fs = pointFilePath.getFileSystem(conf); FSDataInputStream in = fs.open(pointFilePath); runQR(trainingDataFiles, conf, context); LOG.info("Total iterations in master view: " + (System.currentTimeMillis() - startTime)); this.freeMemory(); this.freeConn(); System.gc(); }
From source file:com.flyn.net.asynchttp.DataAsyncHttpResponseHandler.java
/** * Returns byte array of response HttpEntity contents * * @param entity can be null//from w w w.j av a2 s . c o m * @return response entity body or null * @throws java.io.IOException if reading entity or creating byte array failed */ @Override byte[] getResponseData(HttpEntity entity) throws IOException { byte[] responseBody = null; if (entity != null) { InputStream instream = entity.getContent(); if (instream != null) { long contentLength = entity.getContentLength(); if (contentLength > Integer.MAX_VALUE) { throw new IllegalArgumentException("HTTP entity too large to be buffered in memory"); } if (contentLength < 0) { contentLength = BUFFER_SIZE; } try { ByteArrayBuffer buffer = new ByteArrayBuffer((int) contentLength); try { byte[] tmp = new byte[BUFFER_SIZE]; int l; // do not send messages if request has been cancelled while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) { buffer.append(tmp, 0, l); sendProgressDataMessage(copyOfRange(tmp, 0, l)); } } finally { instream.close(); } responseBody = buffer.toByteArray(); } catch (OutOfMemoryError e) { System.gc(); throw new IOException("File too large to fit into available memory"); } } } return responseBody; }
From source file:com.midisheetmusicmemo.ChooseSongActivity.java
public static void logHeap() { Double allocated = new Double(Debug.getNativeHeapAllocatedSize()) / new Double((1048576)); Double available = new Double(Debug.getNativeHeapSize()) / 1048576.0f; Double free = new Double(Debug.getNativeHeapFreeSize()) / 1048576.0f; DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);//from w w w. jav a 2 s. c o m df.setMinimumFractionDigits(2); Log.d("blah", "debug. ================================="); Log.d("blah", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)"); Log.d("blah", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory() / 1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)"); System.gc(); System.gc(); }
From source file:com.h3xstream.findbugs.test.BaseDetectorTest.java
@AfterClass public void after() { System.gc(); if (DEBUG) {/*from w ww . j a va2s.c o m*/ Runtime rt = Runtime.getRuntime(); long inMb = 1024 * 1024; log.info("=== Memory info (Process " + ManagementFactory.getRuntimeMXBean().getName() + ") ==="); log.info("Total memory : " + rt.totalMemory() / inMb); log.info("Free memory : " + rt.freeMemory() / inMb); log.info("Memory usage : " + (rt.totalMemory() - rt.freeMemory()) / inMb); log.info("==================="); } // for(Object mock : mocksToReset) { // reset(mock); // } // mocksToReset.clear(); }
From source file:com.imagelake.android.account.Servlet_Account.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from w ww .jav a 2 s . c om String uid = request.getParameter("uid"); if (uid != null) { User u = udi.getUser(Integer.parseInt(uid)); if (u != null) { if (u.getState() == 1) { JSONObject jo = new JSONObject();//create a JSONObject if (u.getUser_type() != 2 && u.getUser_type() != 3) { double income = 0.0; DecimalFormat df = new DecimalFormat("#.00"); try { String sql = "SELECT SUM(total) FROM admin_package_income"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { income = rs.getDouble(1); jo.put("income", df.format(income)); } rs.close(); } catch (Exception e) { e.printStackTrace(); } int usersCount = udi.allUsersCount(); jo.put("users", usersCount); int imagesCount = new ImagesDAOImp().getImagesCount(); jo.put("imgcount", imagesCount); } else { UserHasPackage uss = uhpdi.getUserActivePackage(u.getUser_id(), 1); //check user package------------------------------------------- if (uss != null) { System.out.println(uss.getExpire_date()); System.out.println(date); System.out.println("is expierd:" + uss.getExpire_date().compareTo(date)); if (uss.getExpire_date().compareTo(date) <= 0) { boolean okk = new UserHasPackageDAOImp().updateState(uss.getUhp_id()); } else { if (!uss.getLast_date().equals(date)) { if (uss.getPackage_type() == 1) { //FreeTrial f=new FreeTrialDAOImp().getAFreeTrail(uss.getPackage_type()); UserHasPackage uhpp = new UserHasPackage(); uhpp.setDownload_count(uss.getOrg_downloads()); uhpp.setCredit_count(uss.getCredit_count()); uhpp.setLast_date(date); uhpp.setUhp_id(uss.getUhp_id()); System.gc(); boolean kk = new UserHasPackageDAOImp().updatePackage(uhpp); System.out .println("UPDATE PACKAGE | PACKAGE TYPE IS 1 7 DAY FREE TRIAL"); } else if (uss.getPackage_type() == 2) { //FreeTrial f=new FreeTrialDAOImp().getAFreeTrail(uss.getPackage_type()); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, uss.getDuration()); UserHasPackage uhpp = new UserHasPackage(); System.out.println( "*******************" + uss.getExpire_date().compareTo(date)); if (uss.getExpire_date().compareTo(date) < 0) { uhpp.setDownload_count(uss.getDownload_count()); uhpp.setCredit_count(uss.getCredit_count()); uhpp.setExpire_date(sdf.format(c.getTime())); uhpp.setLast_date(date); uhpp.setUhp_id(uss.getUhp_id()); System.gc(); boolean kk = new UserHasPackageDAOImp().updateExpireDate(uhpp); System.out.println( "UPDATE EXPIRE DATE | PACKAGE TYPE IS 2 MONTH FREE TRIAL"); } else { uhpp.setDownload_count(uss.getDownload_count()); uhpp.setCredit_count(uss.getCredit_count()); uhpp.setExpire_date(sdf.format(c.getTime())); uhpp.setLast_date(date); uhpp.setUhp_id(uss.getUhp_id()); System.gc(); boolean kk = new UserHasPackageDAOImp().updatePackage(uhpp); System.out.println( "UPDATE JUST LAST DATE | PACKAGE TYPE IS 2 MONTH FREE TRIAL"); } } else if (uss.getPackage_type() == 3) { SubscriptionPackage sp = new SubscriptionPackageDAOImp() .getSubscription(uss.getPackage_id()); if (sp.getSubscription_type_id() != 2) { //DownloadCount dc=new DownloadCountDAOImp().getCount(sp.getCount_id()); UserHasPackage uhpp = new UserHasPackage(); uhpp.setDownload_count(uss.getOrg_downloads()); uhpp.setCredit_count(uss.getCredit_count()); uhpp.setLast_date(date); uhpp.setUhp_id(uss.getUhp_id()); System.gc(); boolean kk = new UserHasPackageDAOImp().updatePackage(uhpp); System.out.println( "UPDATE PACKAGE | PACKAGE TYPE IS 3 SUBSCRIPTION PACKAGE"); } } } } } // UserHasPackage up = uhpdi.getUserPackage(u.getUser_id(), 1, 3); if (up == null) { jo.put("subscription", "Image Subscription"); jo.put("ps1", "You have no active image subscriptions"); jo.put("issNull", "yes"); } else { SubscriptionPackage sp = spdi.getSubscription(up.getPackage_id()); String type = spdi.getSubscriptionType(sp.getSubscription_type_id()); String title = uhpdi.getPackageType(up.getPackage_type()); DownloadCount dc = dcdi.getCount(sp.getCount_id()); int dowPerDay = dc.getCount(); jo.put("subscription", "" + dowPerDay + " images " + type + " " + title + " for " + sp.getDuration() + " Month"); jo.put("ps1", "Purchase Date : " + up.getPurchase_date()); jo.put("ps2", "Expire Date : " + up.getExpire_date()); jo.put("ps3", "you have left " + up.getDownload_count() + " downloads for today"); jo.put("issNull", "no"); } UserHasPackage p = uhpdi.getUserPackage(u.getUser_id(), 1, 4); if (p == null) { jo.put("credits", "Image Credit Packs"); jo.put("pc1", "You have no active credit packs"); jo.put("iscNull", "yes"); // jo.put("pckType","2"); } else { SubscriptionPackage sp = spdi.getSubscription(p.getPackage_id()); String title = uhpdi.getPackageType(p.getPackage_type()); jo.put("credits", p.getCredit_count() + " " + title + " Package"); jo.put("pc1", "Purchase Date : " + p.getPurchase_date()); jo.put("pc2", "Expire Date : " + p.getExpire_date()); jo.put("pc3", "you have left " + p.getCredit_count() + " credits for today"); jo.put("iscNull", "no"); // jo.put("pckType","2"); } } out.write("json=" + jo.toJSONString()); System.out.println("json" + jo.toJSONString()); } else { out.write("msg=Blocked by the admin"); } } else { out.write("msg=Internal server error,Please try again later."); } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:di.uniba.it.tee2.extraction.TemporalExtractor.java
public void close() { heidelTagger = null; System.gc(); }
From source file:org.dkpro.lab.engine.impl.DefaultLifeCycleManager.java
@Override public void complete(TaskContext aContext, Task aConfiguration) throws LifeCycleException { aContext.getMetadata().setEnd(System.currentTimeMillis()); aContext.message("Completing task [" + aConfiguration.getType() + "]"); aContext.message("Running reports for task [" + aConfiguration.getType() + "]"); List<Class<? extends Report>> reports = new ArrayList<Class<? extends Report>>(aConfiguration.getReports()); Collections.sort(reports, new Comparator<Class<?>>() { @Override// w ww.j a v a2 s. c o m public int compare(Class<?> aO1, Class<?> aO2) { return aO1.getName().compareTo(aO2.getName()); } }); int i = 1; for (Class<? extends Report> reportClass : reports) { for (int g = 0; g < 3; g++) { System.gc(); } try { aContext.message( "Starting report [" + reportClass.getName() + "] (" + i + "/" + reports.size() + ")"); Report report = reportClass.newInstance(); report.setContext(aContext); report.execute(); aContext.message( "Report complete [" + reportClass.getName() + "] (" + i + "/" + reports.size() + ")"); } catch (Exception e) { aContext.error("Report failed [" + reportClass.getName() + "] (" + i + "/" + reports.size() + ")", e); throw new LifeCycleException(e); } finally { i++; } } // This is a critical file as it marks if a task has completed successfully or not. If // this file cannot be created properly, e.g. because the disk is full, then there will be // subsequent and hard to debug errors. Thus, if the file cannot be created properly, any // potentially incomplete version of this file has to be deleted. try { aContext.storeBinary(TaskContextMetadata.METADATA_KEY, aContext.getMetadata()); } catch (Throwable e) { aContext.getStorageService().delete(aContext.getId(), TaskContextMetadata.METADATA_KEY); throw new LifeCycleException( "Unable to write [" + TaskContextMetadata.METADATA_KEY + "] to mark context as complete.", e); } aContext.message("Completed task [" + aConfiguration.getType() + "]"); }
From source file:edu.iu.daal_ridgereg.RidgeRegDaalCollectiveMapper.java
protected void mapCollective(KeyValReader reader, Context context) throws IOException, InterruptedException { long startTime = System.currentTimeMillis(); List<String> trainingDataFiles = new LinkedList<String>(); //splitting files between mapper while (reader.nextKeyValue()) { String key = reader.getCurrentKey(); String value = reader.getCurrentValue(); LOG.info("Key: " + key + ", Value: " + value); System.out.println("file name : " + value); trainingDataFiles.add(value);//from w w w.j a va 2s . c o m } Configuration conf = context.getConfiguration(); Path pointFilePath = new Path(trainingDataFiles.get(0)); System.out.println("path = " + pointFilePath.getName()); FileSystem fs = pointFilePath.getFileSystem(conf); FSDataInputStream in = fs.open(pointFilePath); runRidgeReg(trainingDataFiles, conf, context); LOG.info("Total iterations in master view: " + (System.currentTimeMillis() - startTime)); this.freeMemory(); this.freeConn(); System.gc(); }
From source file:edu.iu.daal_linreg.LinRegDaalCollectiveMapper.java
protected void mapCollective(KeyValReader reader, Context context) throws IOException, InterruptedException { long startTime = System.currentTimeMillis(); List<String> trainingDataFiles = new LinkedList<String>(); //splitting files between mapper while (reader.nextKeyValue()) { String key = reader.getCurrentKey(); String value = reader.getCurrentValue(); LOG.info("Key: " + key + ", Value: " + value); System.out.println("file name : " + value); trainingDataFiles.add(value);/* ww w . j a v a 2s .co m*/ } Configuration conf = context.getConfiguration(); Path pointFilePath = new Path(trainingDataFiles.get(0)); System.out.println("path = " + pointFilePath.getName()); FileSystem fs = pointFilePath.getFileSystem(conf); FSDataInputStream in = fs.open(pointFilePath); runLinReg(trainingDataFiles, conf, context); LOG.info("Total iterations in master view: " + (System.currentTimeMillis() - startTime)); this.freeMemory(); this.freeConn(); System.gc(); }