In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how to monitor JVM available memory in JSP, concise and easy to understand, definitely can make your eyes shine, through the detailed introduction of this article I hope you can gain something.
The company has a JSP project memory often overflow,tomcat stopped about two hours, I wrote a class to monitor the JVM available memory
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
Title:GCTimerTask
* @author zhuangyan
* @msn:nacl_zhuang@hotmail.com
* @qq:368924454
* @version 1.0
*/
public class GCTimerTask
extends TimerTask {
private static GCTimerTask instance = null;
public void run() {
Calendar cal = new GregorianCalendar();
int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0.. 23
int min = cal.get(Calendar.MINUTE); // 0.. 59
System.out.print("["+String.valueOf(hour24)+":"+String.valueOf(min)+"]");
System.out.println("JVM free memory:" + java.lang.Runtime.getRuntime().
freeMemory() / (1024*1024)+"M/"+java.lang.Runtime.getRuntime()
.totalMemory()/(1024*1024)+"M" );
System.gc();
}
private void startWork()
{
Timer t = new Timer();
t.schedule(instance,0,1000*60);
}
public static GCTimerTask getInstance()
{
if(instance==null) {
instance = new GCTimerTask();
instance.startWork();
}
return instance;
}
}
This class is simple, but beginners should learn from it.
1) Usage of timer class
2)java.lang.Runtime.getRuntime().freeMemory(),java.lang.Runtime.getRuntime().totalMemory(),System.gc()
The use of these three methods, it should be noted that System.gc() does not force the JVM to immediately free memory, if that, my memory overflow problem has been solved.
3)getInstance() Singleton pattern,
4)*** is how to use this class problem, I put it into the EncodingFilter class, now many JSP programs have this class bar
public final void init(final FilterConfig arg0) throws ServletException { GCTimerTask.getInstance(); this.filterConfig = arg0; this.encoding = filterConfig.getInitParameter("encoding"); String value = filterConfig.getInitParameter("ignore"); if (value == null) { this.ignore = true; } else if (value.equalsIgnoreCase("true")) { this.ignore = true; } else if (value.equalsIgnoreCase("yes")) { this.ignore = true; } else { this.ignore = false; } }
JVM available memory:405 MB/508 MB
java.lang.OutOfMemoryError
Why does it show that JVM has more than 400 M of free memory and OutOfMemoryError? In the window resource manager to see tomcat memory usage is continuously increasing, it and java.lang.Runtime.getRuntime().freeMemory() is what difference ah?
JSP overflow in the window resource manager tomcat memory accounted for more than 300 M,MSSQL memory is almost to 300M. Is there any way to restart these two services on a regular basis? I wrote a procedure available under XP. But it doesn't work under 2000.
What is it like to monitor JVM memory available in JSP? Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.