使用google perf工具来排查堆外内存占用

现象

线上机器内存不足,经常被系统oom killer干掉。

如果tomcat运行的好好的,突然被干掉了,没有任何线索,那么就可以使用下面的命令看看是不是oom killer搞的鬼

阅读更多

jinfo使用

查看最终生效的flag

sudo -u tomcat jinfo pid

1
2
3
4
5
6
7
8
9
10
11
12
13
Attaching to process ID 30350, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.45-b08
...
...
sun.cpu.endian = little
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans.
sun.cpu.isalist =

VM Flags:

-Djava.util.logging.config.file=/tomcat/www/application/conf/logging.properties -Xms6g -Xmx6g -Xmn4g -XX:PermSize=256m -XX:MaxPermSize=256M ... -Djava.io.tmpdir=/tomcat/www/application/temp

阅读更多

executor总结

shutdown()和shutdownNow()

shutdown()

shutdown()会尝试中断空闲的线程,并把ThreadPool的状态置成SHUTDOWN,
这个状态下,不能通过submit()或者execute()提交任务,但是正在执行的和任务队列中的任务还可以继续执行。

阅读更多

Guava中的ThreadFactoryBuilder

用法

java中自定义线程池时可以传入一个ThreadFactory,用来创建线程。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Creates a new {@code ThreadPoolExecutor} with the given initial
* parameters and default rejected execution handler.
*
* @param corePoolSize the number of threads to keep in the pool, even
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
* @param maximumPoolSize the maximum number of threads to allow in the
* pool
* @param keepAliveTime when the number of threads is greater than
* the core, this is the maximum time that excess idle threads
* will wait for new tasks before terminating.
* @param unit the time unit for the {@code keepAliveTime} argument
* @param workQueue the queue to use for holding tasks before they are
* executed. This queue will hold only the {@code Runnable}
* tasks submitted by the {@code execute} method.
* @param threadFactory the factory to use when the executor
* creates a new thread
* @throws IllegalArgumentException if one of the following holds:<br>
* {@code corePoolSize < 0}<br>
* {@code keepAliveTime < 0}<br>
* {@code maximumPoolSize <= 0}<br>
* {@code maximumPoolSize < corePoolSize}
* @throws NullPointerException if {@code workQueue}
* or {@code threadFactory} is null
*/
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory) {
this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
threadFactory, defaultHandler);
}

阅读更多

MAT-Ubuntu无法打开Report

现象

可以运行Leak Suspects,可以看到报告文件确实生成了,但是无法打开,看error log如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Unhandled event loop exception

org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTError: No more handles [Browser style SWT.MOZILLA and Java system property org.eclipse.swt.browser.DefaultType=mozilla are not supported with GTK 3 as XULRunner is not ported for GTK 3 yet])
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3794)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3433)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.mat.ui.rcp.Application.start(Application.java:26)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: org.eclipse.swt.SWTError: No more handles [Browser style SWT.MOZILLA and Java system property org.eclipse.swt.browser.DefaultType=mozilla are not supported with GTK 3 as XULRunner is not ported for GTK 3 yet]
at org.eclipse.swt.SWT.error(SWT.java:4517)
at org.eclipse.swt.browser.MozillaDelegate.<init>(MozillaDelegate.java:57)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:663)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
at org.eclipse.mat.ui.internal.panes.QueryTextResultPane.createPartControl(QueryTextResultPane.java:72)
at org.eclipse.mat.ui.editor.MultiPaneEditor.addPage(MultiPaneEditor.java:585)
at org.eclipse.mat.ui.editor.MultiPaneEditor.addPage(MultiPaneEditor.java:574)
at org.eclipse.mat.ui.editor.MultiPaneEditor.addNewPage(MultiPaneEditor.java:496)
at org.eclipse.mat.ui.QueryExecution.doDisplayResult(QueryExecution.java:300)
at org.eclipse.mat.ui.QueryExecution.access$0(QueryExecution.java:240)
at org.eclipse.mat.ui.QueryExecution$1.run(QueryExecution.java:144)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 24 more

阅读更多

使用greys来排查线上问题

greys

greys的理念是将btrace常用的功能命令化,这样可以大大的节省排查问题的时间。

greys 安装

推荐使用网络安装:

阅读更多

java8 Stream使用不当,导致文件没有关闭

现象

线上巡查的时候,检查了线上机器的tomcat打开的文件列表,发现了一些问题。
一般来说,tomcat打开的文件就是一些jar包,日志文件, 动态库,socket等。因此用下面的命令查看下tomcat打开的文件

阅读更多