屠龙的技能

生产服务器 的 jvm 的 load 上周终于 高了……
一台机器 表现 不正常

最幸福的 事情 就是 有屠龙的技能 也要找到 龙了

然后 就将学来 的 分析 jvm 寻找 load  高的技能 施展了一下

以前 用 木庄 练习 实在是没劲

实际再 生产机器 上 动手还是 有困难的

 

笔记

thread dump

很多 文档 都说 kill -3 PID

其实 没啥不对 关键 当时比较 傻 将 std 打到 /dev/null 里边去了

后来 发现 jstack (jdk自带) 比 kill -3 牛逼 多了

还能 force dump (pid 没响应了)

 

拿到 thread dump 就是 top -H 了

第一次 弄 忘记了 -H 呵呵 不过 发现进程 少了 很快就发现了

 

拿到 nid 转 16进制 然后 马上 就发现 bug 所在了

 

 

比老师 Bluedavy  在书中 就是 感谢 有关部门 提供 机会

实践想法 才得到 成长的

我 这里也感谢 有关部门 提供 支持

顺便 感谢 前几次 故障 内存漏了 句柄漏了 ……

机会留给有准备的 淫

Read More

JBoss 远程 Jndi 链接 数据源 ibatis 出异常的解决

JBoss 数据源默认 JNDI 默认 是不能 跨VM 提供的

需要加一句<use-java-context>false</use-java-context>

 

这样 创建的数据源 没啥问题 也可以用 但是 ibatis 使用就有问题

java.sql.SQLException does not return Serializable

 

这个 问题 我找到了 同样的描述就是

http://stackoverflow.com/questions/39053/accessing-datasource-from-outside-a-web-container-through-jndi

 

我没找到正确的解决方案 就用 jdk 的 Proxy 给 它打了 一个 补丁…… 然后 就艺了

 

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * @author jiaoyi 通过 JNDI 远程链接 JBoss 的数据源 会有问题 抛出
 *         java.lang.IllegalAccessException: Method=public abstract
 *         java.sql.Connection java.sql.Statement.getConnection() throws
 *         java.sql.SQLException does not return Serializable
 *
 *         这个 家伙 通过hook 代码 将 原始的 Connection 返回给上层 解决这个问题
 *
 */

public class JndiDataSourceProxy implements FactoryBean {
    private static final ClassLoader THIS_LOADER = JndiDataSourceProxy.class
            .getClassLoader();

    private Object jndiObject;

    public void setJndiObject(Object jndiObject) {
        this.jndiObject = jndiObject;
    }

    private class StatementHandler implements InvocationHandler {
        private DataSource ds = (DataSource) jndiObject;
        private Object target;

        StatementHandler(Object target) {
            this.target = target;
        }

        public Object invoke(Object proxy, Method method, Object[] args)
                throws Throwable {
            if ("getConnection".equals(method.getName())) {
                return ds.getConnection();
            }
            return method.invoke(target, args);
        }

    }

    private class ConnectionHandler implements InvocationHandler {
        private Connection target;

        ConnectionHandler(Connection target) {
            this.target = target;
        }

        public Object invoke(Object proxy, Method method, Object[] args)
                throws Throwable {

            if ("prepareStatement".equals(method.getName())) {
                return (Statement) Proxy.newProxyInstance(THIS_LOADER,
                        new Class[] { PreparedStatement.class },
                        new StatementHandler(method.invoke(target, args)));
            }
            return method.invoke(target, args);
        }

    }

    private class DataSourceHandler implements InvocationHandler {
        private DataSource ds = (DataSource) jndiObject;

        public Object invoke(Object proxy, Method method, Object[] args)
                throws Throwable {
            if ("getConnection".equals(method.getName())) {
                return (Connection) Proxy.newProxyInstance(THIS_LOADER,
                        new Class[] { Connection.class },
                        new ConnectionHandler(ds.getConnection()));
            }

            return method.invoke(JndiDataSourceProxy.this.jndiObject, args);
        }

    }

    public Object getObject() throws Exception {
        return (DataSource) Proxy.newProxyInstance(THIS_LOADER,
                new Class[] { DataSource.class }, new DataSourceHandler());
    }

    public Class<DataSource> getObjectType() {
        return DataSource.class;
    }

    public boolean isSingleton() {
        return true;
    }

}

使用时候用这个 包上就行了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    <bean id="oracleDataSource" class="com.taobao.btc.mario.jndi.JndiDataSourceProxy">
        <property name="jndiObject">
            <bean class="org.springframework.jndi.JndiObjectFactoryBean">
                <property name="jndiName" value="java:YourDS" />
                <property name="jndiEnvironment">
                    <props>
                        <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
                        <prop key="java.naming.provider.url">jnp://127.0.0.1:1099</prop>
                        <prop key="java.naming.factory.url.pkgs">org.jboss.namingrg.jnp.interfaces</prop>
                        <prop key="jnp.disableDiscovery">true</prop>
                    </props>
                </property>
            </bean>
        </property>
    </bean>
Read More

ubuntu 升级导致eclipse插件挂掉

实验后 增加

org.eclipse.update.reconcile=true

解决问题

参考 位置

http://www.blogjava.net/eagle-daiq/articles/280230.html

Read More

调整JVM解决JBoss无法访问实践

最近发现JBoss 启动一个以前的应用 访问速度及其慢
而且 只能打开一下 然后就不能用了

观察日志 无任何异常

开始考虑是数据库链接问题
不过一直无法证明

后来通过 debug 跟踪 发现 程序居然 运行时抛出的 OutOfMemory异常
但是异常在 页面生成之前被吃掉了

jstat 分析后 发现 P区 99%
调整P区大小后 问题解决

Read More

JBoss 中文乱码的一些解决方案

前提 GBK 编码
其他 可以参考

* 给系统加 Lang = zh_CN.GBK …

如果不行

* 强制JVM编码

/bin/run.conf +

JAVA_OPTS=”$JAVA_OPTS -Dsun.jnu.encoding=GBK -Dfile.encoding=GBK”

如果还不行

* 强制过滤器 web.xml


encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding GBK

forceEncoding true



encodingFilter
/*

我靠 有才 还不行

* 强制 URI编码

tomcat 的恶 server.xml

还不行……
改用英文程序把 不会有问题

Read More

decorateTransform 找不到 jboss 4.2.2

方式 使用了
TransformedMap.decorateTransform 在单元测试时候没有任何问题

在 实际运用时候居然抛出了
java.lang.NoSuchMethodError: org.apache.commons.collections.map.TransformedMap.decorateTransform(Ljava/util/Map;Lorg/apache/commons/collections/Transformer;L org/apache/commons/collections/Transformer;)Ljava/util/Map

这个让我非常郁闷
后来
for (Method m : TransformedMap.class.getDeclaredMethods()){
System.out.println(m.toString());
}

发现果然 没有…… 对啊 不可能有阿

疑点 转移到 jboss身上

发现 jboss /server /default /lib 下居然……
commons-collections.jar 居然有这个……

太可怕了

Read More

JBoss 在eclispe 中启动超时

在eclipse众配置JBOss

Server JBoss v4.2 at localhost was unable to start within 50 seconds. If the server requires more time, try increasing the timeout in the server editor.

启动后发现超时

发现大家的解决办法居然是 把超时时间设置为 1天

我觉得这样不合理

经过查找 发现还是 美地 愿意解决问题

http://stackoverflow.com/questions/298312/starting-jboss-from-eclipse/1358404#1358404

将 主机名字改 ip就可以了

估计是 无法监控到状态引起的

Read More