Recently in java Category

为了获得web-app目录中的.properties文件,需要先取得web-app的WEB-INF目录,网上有很多的方法,大致描述如下:

1、java程序中中获得
System.out.println("1"+Thread.currentThread().getContextClassLoader().getResource(""));
System.out.println("2"+TestPath.class.getResource(""));
System.out.println("3"+TestPath.class.getResource("/"));
System.out.println("4"+TestPath.class.getClassLoader().getResource(""));
System.out.println("5"+ClassLoader.getSystemResource(""));
System.out.println("6"+TestPath.class.getClassLoader().getResource("src.com.2hei.net.util"));
System.out.println("7"+new File("").getAbsolutePath());


2、在jsp中获得web-app目录


根目录:request.getRequestURI()
文件的绝对路径  :application.getRealPath(request.getRequestURI());
当前web应用的绝对路径 :application.getRealPath("/");


3、Servlet中获得当前应用的相对路径和绝对路径
根目录:request.getServletPath();
文件的绝对路径 :
javax.servlet.http.HttpSession.getServletContext()
request.getSession().getServletContext().getRealPath
当前web应用的绝对路径 :servletConfig.getServletContext().getRealPath("/");

但是我遇到的问题是使用java来获得web-app目录始终得到的是容器的root目录,比如我使用的是resin3.1.6,使用java程序获得的目录始终都是/home/resin-3.1.6。
想尽了办法,把caucho.com的文档翻了个遍,也尝试了class-loader等resource等配置,始终无法配置好,我又不想使用jsp或者servlet来获取,于是想到了如下的土办法。

resin.conf 或者resin.xml中配置(详见resin-doc)
  <env-entry>
    <env-entry-name>greeting</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>I‘m 2hei</env-entry-value>
  </env-entry>


调用方法:
  public void init()
    throws ServletException
  {
    try {
      Context env =
        (Context) new InitialContext().lookup("java:comp/env");
      greeting = (String) env.lookup("greeting");
    } catch (NamingException e) {
      throw new ServletException(e);
    }
  }
然而,见证奇迹的时刻终于到来了!
现有java文件编译后是给打成了jar包来进行发布,放到了WEB-INF/lib目录中,这样使用java获得的web-app位置就是resin的home目录
我尝试不打jar包,将class放到WEB-INF/classes中,使用java来获取应用程序的绝对路径居然可以了,真不知道resin是如何加载jar包的。汗ing。。。

不过既然问题解决了,就此记录下来,以作备忘。

再者,今天是2.14 情人节,就祝愿天下有情人终成眷属!
| | Comments (0) | TrackBacks (0)
#cat stdout.log
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
 java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:66)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2690)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2619)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1552)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1162)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1079)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1064)
    
   
线上跑的java应用中的stderr.log中偶尔会有这样的日志出现,出现问题时系统负载并不高,并且系统可以自己恢复正常。google了很久,也困扰俺多日,今天对这个问题做一个了断。

产生这个问题的原因可能有以下几个:
1、mysql的驱动的问题,我的驱动是mysql-connector-java-3.1.11-bin.jar
如果有兴趣测试话,可以使用其他新版本的mysql驱动来试试吧。

2、防火墙和网络上的问题
,或者服务器发生了crash(有意或无意导致)
同学们可以检查产生"java.net.SocketException: Broken pipe" 错误的时候服务器、网络是否有异常?

3、应用系统的数据库连接池导致,
最大的可能就是程序上写的不严谨  吼吼!
新手在开发过程中都难避免的失误:忘记数据库连接的关闭(纯jdbc的操作中常见,不过这个还好找啦,压力测试中如果看到数据库连接数多或者干脆挂掉可以找出原因的);
另外就是提交事物时,在对数据操作中没有做明确的commit或者rollback,如果忘记了提交commit,在你尝试使用类似的resultset去操作或者做其他的操作时就有可以能出现这样的问题,这样的悬挂着连接一直要等到超时mysql将其kill掉。仔细检查你应用的事物中是否都做了明确的提交操作呢?或者干错使用Hibernate,试试C3P0、Proxool这样的连接池吧。
 
| | Comments (0) | TrackBacks (1)
错误症状:

500 Servlet Exception
java.lang.InternalError: Can't connect to X11 window server using 'localhost:0.0'
as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
    at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
    at java.lang.Thread.run(Thread.java:534)

google了半天,试过了安装xorg-x11-Xvfb包,export DISPLAY=:0等等,无奈,没有解决。
最后终于找到了解决方案:
可以在java的jvm上 加入参数   –Djava.awt.headless=true

| | Comments (0) | TrackBacks (0)


使用Volano对jvm性能测试

网络测试报告:
http://www.volano.com/report/index.html

一、以下是2hei的测试情况:
原理:
启动volano server 会根据jdk的版本来设定默认的jvm值,然后启动简化版的Tomcat,并部署VolanoChat聊天系统;
启动客户端对VolanoChat进行连接,客户端模拟聊天者并发发送大量的消息,来测试jvm的性能。


使用JDK1.6

设定1.6的环境变量
export JAVA_HOME=/home/jdk1.6.0_06
export PATH=$JAVA_HOME/bin:$PATH

启动server:

./loopserver.sh sun16
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

/home/jdk1.6.0_06/bin/java -server -Xmx64m -Dinstall.root=. -Dcatalina.home=. -cp .:lib/bootstrap.jar:lib/catalina.jar:lib/naming-common.jar:lib/naming-resources.jar:lib/servlet.jar:lib/servlets-common.jar:lib/servlets-default.jar:lib/volanochat-server.jar:lib/xerces.jar COM.volano.Main

VolanoChat(TM) Server Version 2.5.0.9
Copyright (C) 1996-2002 Volano LLC.  All rights reserved.
Loading server properties from "/home/www.2hei.net/soft/voooo/conf/properties.txt".
www.2hei.net:8000  VolanoChatPro - unlimited connections.
Apache Tomcat/4.0.3

启动client,对server进行压力测试
./loopclient.sh sun16

ulimit -Sn = 1024

java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

/home/jdk1.6.0_06/bin/java -server -Xmx64m -Dinstall.root=. -Dcatalina.home=. -cp .:lib/bootstrap.jar:lib/catalina.jar:lib/naming-common.jar:lib/naming-resources.jar:lib/servlet.jar:lib/servlets-common.jar:lib/servlets-default.jar:lib/volanochat-server.jar:lib/xerces.jar COM.volano.Mark -run

执行结果:
java.vendor        = Sun Microsystems Inc.
java.vendor.url    = http://java.sun.com/
java.version       = 1.6.0_06
java.class.version = 50.0
java.compiler      = null
os.name            = Linux
os.version         = 2.6.9-67.0.15.ELsmp
os.arch            = i386

VolanoMark version = 2.5.0.9
Messages sent      = 20000
Messages received  = 380000
Total messages     = 400000
Elapsed time       = 12.862 seconds
Average throughput = 31099 messages per second


使用JDK1.4:

设定1.4的环境变量
export JAVA_HOME=/home/j2sdk1.4.2_17
export PATH=$JAVA_HOME/bin:$PATH

./loopserver.sh sun14
ulimit -Sn = 1024

java version "1.4.2_17"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_17-b06)
Java HotSpot(TM) Server VM (build 1.4.2_17-b06, mixed mode)

/home/j2sdk1.4.2_17/bin/java -server -Xmx64m -Dinstall.root=. -Dcatalina.home=. -cp .:lib/bootstrap.jar:lib/catalina.jar:lib/naming-common.jar:lib/naming-resources.jar:lib/servlet.jar:lib/servlets-common.jar:lib/servlets-default.jar:lib/volanochat-server.jar:lib/xerces.jar COM.volano.Main

VolanoChat(TM) Server Version 2.5.0.9
Copyright (C) 1996-2002 Volano LLC.  All rights reserved.
Loading server properties from "/home/www.2hei.net/soft/voooo/conf/properties.txt".
www.2hei.net:8000  VolanoChatPro - unlimited connections.
Apache Tomcat/4.0.3

./loopclient.sh sun14
ulimit -Sn = 1024

java version "1.4.2_17"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_17-b06)
Java HotSpot(TM) Server VM (build 1.4.2_17-b06, mixed mode)

/home/j2sdk1.4.2_17/bin/java -server -Xmx64m -Dinstall.root=. -Dcatalina.home=. -cp .:lib/bootstrap.jar:lib/catalina.jar:lib/naming-common.jar:lib/naming-resources.jar:lib/servlet.jar:lib/servlets-common.jar:lib/servlets-default.jar:lib/volanochat-server.jar:lib/xerces.jar COM.volano.Mark -run

执行结果:
java.vendor        = Sun Microsystems Inc.
java.vendor.url    = http://java.sun.com/
java.version       = 1.4.2_17
java.class.version = 48.0
java.compiler      = null
os.name            = Linux
os.version         = 2.6.9-67.0.15.ELsmp
os.arch            = i386

VolanoMark version = 2.5.0.9
Messages sent      = 20000
Messages received  = 380000
Total messages     = 400000
Elapsed time       = 15.739 seconds
Average throughput = 25415 messages per second


二、测试结论:

在同等的硬件配置及操作系统下,测试每次都发送400000条数据,从执行时间和吞吐量上看jdk1.6的性能要比jdk1.4的高一些,
如吞吐量分别是每秒31099,25415。

 

网上其他的关于jdk性能的比较

下面是sun对与J2SE 1.4.2 和J2SE 5.0的性能比较

http://java.sun.com/performance/reference/whitepapers/5.0_performance.html

sun五个升级到jdk1.5的原因。  比如性能优化,稳定性优化,还有64位的支持等等

http://java.sun.com/developer/technicalArticles/J2SE/5reasons.html

| | Comments (0) | TrackBacks (0)

 

JDK1.5提供JMX remote的管理工具Jconsole,可以监控Java运行程序的内存使用情况、活动线程数量、类装载的数量、MBeans的状态、虚拟机的各种信息等,还可以执行MBean公开的方法或强制进行垃圾回收。因为Apusic应用服务器实现标准的JMX接口,因此也可以使用Jconsole进行监控。

下面是在windows端对Linux的java应用(Resin)的JVM进行监控。
windows: 安装 jdk1.6.0_06  http://java.sun.com/javase/downloads/index.jsp
Linux:Resin2.1.x + jdk1.6

启动resin ,增加jvm监控的指令:
可以在java启动参数添加,
如: httpd.sh  或者 wrapper.pl 里面
vi http.sh
args="***" 把 需要启动jvm选项加入。

#指定远程服务器的端口
-Dcom.sun.management.jmxremote.port=12345
#指定远程服务器的用户认证
-Dcom.sun.management.jmxremote.password.file=$JRE_HOME/lib/management/password.properties
-Dcom.sun.management.jmxremote.access.file=$JRE_HOME/lib/management/access.properties

使用密码:
#JRE_HOME/lib/management/jmxremote.password.template
cp jmxremote.password.template password.properties
chmod 600 password.properties
#默认用户名 密码为:
monitorRole QED
controlRole R&D
#默认权限
#cp jmxremote.access access.properties 
#设置权限
monitorRole   readonly
controlRole   readwrite

#也可以使用禁止用户认证
com.sun.management.jmxremote.authenticate=false


也可以使用ssl连接

这里先不用
com.sun.management.jmxremote.ssl=false


说明: 如果没有启动com.sun.management.jmxremote 的配置 , 远程连接会提示:
error during jrmp connection establishment ; nested exception is

如果无法连接有可能是linux服务器的hostname存在问题

#修改hostname
/etc/hosts  把127.0.0.1修改为外网卡IP,如192.168.1.100
还有
/etc/sysconfig/network

#启动resin
$RESIN_HOME/bin/http.sh start
#查看是否已经启动
#ps -x
8681 pts/0    S      0:00 perl bin/wrapper.pl -chdir -name httpd -class com.caucho.server.http.HttpServer -J-server -verbose -Dcom.
8683 pts/0    Sl     0:04 /home/2hei.net/jdk1.6.0_06/bin/java -server -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremo
#查看端口
#netstat -an
tcp        0      0 127.0.0.1:35844             127.0.0.1:35848             ESTABLISHED
tcp        0      0 :::8080                     :::*                        LISTEN
tcp        0      0 :::12345                    :::*                        LISTEN

-Dcom.sun.management.jmxremote.authenticate=false
#是否使用ssl
-Dcom.sun.management.jmxremote.ssl=false"


windows下
jconsole命令在 $JAVA_HOME/bin 下

cmd:\>jconsole
#启动


jvm_6.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

连接远程
192.168.1.100:12345
controlRole R&D

jvm_1.png

 

 

 

 

 

 

 

 

 

 

 

jvm_2.png

 

 

 

 

 

 

 

 

 

 

 

jvm_4.png

 

 

 

 

 

 

 

 

 

 

 

 

参考:
http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html

http://java.sun.com/javase/6/docs/technotes/tools/solaris/keytool.html

| | Comments (0) | TrackBacks (0)
resin更新到3.1.6了,下了一个玩玩

启动的时候
java -jar lib/resin.jar  报错。
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/caucho/boot/ResinBoot (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
       
以前在反编译java代码的时候也遇到过类似的问题,应该是java版本出现了问题。
原来的class或者jar的编译版本比较高。
想起来现有的java版本是j2sdk1.4,升级到jdk1.6.0_06后再启动resin,问题解决。

| | Comments (0) | TrackBacks (0)

 

以前都是把java程序打成一个jar文件,其他关联的jar文件可以放到lib中,加入到classpath中即可。

今天遇到特殊情况了,可执行程序需要使用两个jar文件,按照以往的经验,把第二个jar add进去,其中也不知道点了什么,可能是随手点击了一下set classpath  ,安装后出现了问题,程序跑不起来了。 2hei我遇到问题了,汗!

检查打完包后的安装目录,与exe文件同名字的lax文件,
使用UE打开后,发现如下:
lax.class.path=lax.jar

原来设定的classpath都不见了踪影。可执行文件双击后没有任何反应,程序根本没有起来,手工把相关联的lib文件写进去后,exe文件竟然可以正常跑起来,于是回到install anywhere中寻找问题。

一个一个的排查,终于,在数小时后,发现在Launcher Properties 下的 Edit Properties 按钮下面有设置了lib目录,
lax.class.path 对应的值填写需要的jar及自己打的jar文件
 
安装完成后,再次打开lax文件,
lax.class.path=lib/jdic.jar;lib/org.jar;lib/iText-2.0.7.jar;lib/swing-layout-1.0.jar;lax.jar
问题解决,希望能对使用install anywhere打包的朋友有所帮助。


 

| | Comments (0) | TrackBacks (0)

java 调用dll文件时

几个注意点:
1. package的使用
2. javah的使用
3.path路径的设定

 

下面实例介绍java调用dll中的Max函数:

hello.java

package 2hei.net.dll;

public class hello
{
    static
    {
        //System.out.println(System.getProperties().get("java.library.path"));
        System.loadLibrary("Hello");
    } 
    public native static int Max(int a,int b);
   
    public static void main(String[] args)
    {
        int maxnum = 0;
        int aa = 10;
        int bb = 11;
        hello hi= new hello();
        maxnum = hi.Max(aa,bb);
        System.out.println("max is "+maxnum);        
    }
}

生成.h头文件

createh.bat

cd E:\src\java\2hei\net\dll  

javah hello

会生成一个2hei_net_dll_hello.h的文件

编辑编辑 2hei_net_dll_hello.h  把#include <jni.h> 改成#include "jni.h"

从jdk的目录里面找到jni.h  和 jni_md.h

下面使用VC++生成dll文件。

新建一个dll工程,比如Hello  编辑Hello.cpp

// Hello.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "Hello.h"
#include "2hei_net_dll_hello.h"

JNIEXPORT jint JNICALL 2hei_net_dll_hello_Max
  (JNIEnv *, jclass, jint a, jint b)
{
 if(a>=b)return a;
 else
 return b;
}

编译工程后,在Debug目录中找到Hello.dll文件,放到java的path目录下面。

执行hello.java 即可以得到想要的结果。

 

| | Comments (0) | TrackBacks (0)

今儿个做了一下Linux下resin的访问压力测试,感觉比较好玩,resin独立作为http Server
单点不做任何负载的情况下,resin最高可以坚持到3000访问,访问量在接近4000时http无响应。


测试环境:
FC6 + oralce10g + resin3.1.3
PC机配置: AMD Sempron(tm) Processor 3800+  , 1G RAM
内网环境: Web-Server IP:  172.16.0.252

系统内核:
# uname -a
Linux 2.6.18-1.2798.fc6 #1 SMP Mon Oct 16 14:54:20 EDT 2006 i686 athlon i386 GNU/Linux
系统参数:
more /etc/sysctl.conf
kernel.shmmax = 2147483648 (2G)              #oracle配置时 使用 2G   805306368    #768M               
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
kernel.threads-max = 8192
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
net.core.rmem_max=262144
net.core.wmem_default=262144
net.core.wmem_max=262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack =1
net.ipv4.tcp_window_scaling = 1

相关参数值说明
    (1)shmmax:该参数定义了共享内存段的最大尺寸,因为安装了oracle,将其设置为2G。
    (2)shmmni:这个内核参数用于设置系统范围内共享内存段的最大数量。该参数的默认值是 4096 。通常不需要更改。
    (3)shmall:该参数表示系统一次可以使用的共享内存总量(以页为单位)。缺省值就是2097152,通常不需要修改。
    (4)sem:该参数表示设置的信号量。
    (5)file-max:该参数表示文件句柄的最大数量。文件句柄设置表示在linux系统中可以打开的文件数量。
    (6)threads-max:表示指定内核所能使用的线程的最大数目。


Resin 3.1.3配置
resin.conf

<jvm-arg>-Xmx768m</jvm-arg>
<jvm-arg>-Xss1m</jvm-arg>
<jvm-arg>-Xdebug</jvm-arg>

<memory-free-min>1M</memory-free-min>
<thread-max>10240</thread-max>
<socket-timeout>65s</socket-timeout>
<keepalive-max>128</keepalive-max>
<keepalive-timeout>15s</keepalive-timeout>


因为pro版,需要license,所以使用resin3.1.3开源版。
当测试访问量达到512时,系统无法接受新的请求。
所以需要修改resin源文件,参考网上相关文章。

vi com.caucho.server.port.Port.Port.java
com.caucho.server.port.Port
// Secure override for load-balancers/proxies
  private boolean _isSecure;

  private InetAddress _socketAddress;

  // default timeout
  private long _socketTimeout = DEFAULT;

  private int _connectionMax = 512 ;      改为 10240
  private int _minSpareConnection = 16;

  private int _keepaliveMax = DEFAULT;

编译成功后替换resin.jar相应的类,重启resin服务

使用压力测试工具MS web application: 3000访问.

webapplication.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Top 命令显示如下:

top.png

 

 

 

 

 

 

 

 

 

 

 

vmstat显示:

vmstat.png

 

 

 

 

 

 

 

Load:

logs.png

 

 

resin-status:http://172.16.0.252/resin-status

 

resin-status1.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

数据库连接池
http://172.16.0.252/proxoolAdmins

prx111.png

 

 

 

 

 

 

 

 

#netstat -an|grep ESTABLISHED|wc -l  已经建立的连接数

670

#netstat -an|wc -l     所有连接

2971

压力测试持续了10分钟,结果除了系统负载比较大外(达到了19以上),访问速度和响应还算可以。

达到峰值后的系统,我觉得瓶颈出现在cpu上,达到90%以上。另外系统的tcp连接数量还是根据linux的内核设置有关。虽然已经将resin的http请求线程数放大到了10240,其实这或许只是个理论期望值吧。

不知道还有什么地方可以继续调优的,或许使用resin-pro版本能更加好些?

| | Comments (0) | TrackBacks (0)

proxool 介绍请看:

http://proxool.sourceforge.net/

you can download here!
http://proxool.sourceforge.net/download.html

我的hibernate采用properties方式配置,下面介绍我做的两种配置:

========================
配置一:使用proxool.properties

设置proxool的监控servlet

web.xml

<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>

<init-param>
<param-name>propertyFile</param-name>
<param-value>WEB-INF/classes/Proxool.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Admins</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Admins</servlet-name>
<url-pattern>/Admins</url-pattern>
</servlet-mapping>

2.hibernate.properties  

使用 proxool.properties 配置:

hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.connection.driver_class=oracle.jdbc.OracleDriver
hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
connection.useUnicode=true
connection.characterEncoding=UTF-8
hibernate.show_sql=false
hibernate.connection.provider_class=org.hibernate.connection.ProxoolConnectionProvider
hibernate.proxool.pool_alias DBPool
hibernate.proxool.properties proxool.properties

 

proxool.properties

jdbc-1.proxool.alias=DBPool
jdbc-1.proxool.driver-class=oracle.jdbc.driver.OracleDriver
jdbc-1.proxool.driver-url=jdbc:oracle:thin:@172.10.0.111:1521:2hei
jdbc-1.user=2hei
jdbc-1.password=2hei.net
jdbc-1.proxool.maximum-connection-count=20
jdbc-1.proxool.prototype-count=4
jdbc-1.proxool.house-keeping-test-sql=select sysdate from DUAL
jdbc-1.proxool.verbose=true
jdbc-1.proxool.statistics=10s,1m,1d
jdbc-1.proxool.statistics-log-level=ERROR

配置二:使用proxool.xml

hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.connection.driver_class=oracle.jdbc.OracleDriver
hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
connection.useUnicode=true
connection.characterEncoding=UTF-8
hibernate.show_sql=false
hibernate.connection.provider_class=org.hibernate.connection.ProxoolConnectionProvider
hibernate.proxool.pool_alias DBPool
hibernate.proxool.xmlproxool.xml   ### 与配置的区别

vi classes/proxool.xml

<?xml version="1.0" encoding="utf-8"?>
<something-else-entirely>
<proxool>
<alias>DBPool</alias>
<driver-url>jdbc:oracle:thin:@172.10.0.111:1521:2hei</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties>
<property name="user" value="2hei"/>
<property name="password" value="2hei.net"/>
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<maximum-new-connections>20</maximum-new-connections>
<prototype-count>5</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>10</minimum-connection-count>
<house-keeping-test-sql>select sysdate from dual</house-keeping-test-sql>
</proxool>
</something-else-entirely>

下面是监控记录:

访问http://172.10.0.111/Admins

proxool_1.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

proxool_2.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

proxool_3.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

看到active connection 数量始终为0,以为自己的配置有些问题,

后来采用了压力测试软件,施加点压力(50*10),感觉连接池对数据的压力还是比较敏感,

管理界面显示当available connection 达到最大值后,不会立即消失,而是保持一段时间,

此时的连接数保持较大的数量也应该对服务器不会产生坏影响。

 

| | Comments (0) | TrackBacks (0)

today My Resin's log has some error. make me  mass. 

My site Use Resin3.1.3+Struts2+Hibernate3+oracle10g ...

the website reports the error code of 500

500 Servlet Exception
java.lang.IllegalStateException: sendError() forbidden after buffer has been committed.
 at com.caucho.server.connection.AbstractHttpResponse.sendError(AbstractHttpResponse.java:460)
 at org.apache.struts.action.RequestProcessor.processMapping(RequestProcessor.java:665)
 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:191)
 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
 at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
 at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
 at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:97)
 at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:226)
 at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:488)
 at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:353)
 at com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:957)
 at _jsp._zhengfu._zhijian._xzsp__jsp._jspService(zhengfu/zhijian/xzsp.jsp:131)
 at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
 at com.caucho.jsp.Page.pageservice(Page.java:577)
 at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:190)
 at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:167)
 at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:226)
 at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
 at com.caucho.server.port.TcpConnection.run(TcpConnection.java:477)
 at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:591)
 at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:513)
 at java.lang.Thread.run(Thread.java:619)
=================================

and the jvm's log show this:

java.lang.IllegalStateException: sendError() forbidden after buffer has been committed.
  at com.caucho.server.connection.AbstractHttpResponse.sendError(AbstractHttpResponse.java:485)
  at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:760)
  at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:513)
  at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
  at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:76)
  at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
  at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:241)
  at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
  at com.caucho.server.port.TcpConnection.run(TcpConnection.java:586)
  at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:690)
  at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:612)
  at java.lang.Thread.run(Thread.java:619)

I don't know what's cause this error, may by the struts ?

I find this site about a resin's bug:

http://bugs.caucho.com/view.php?id=1684   resin3.*

thereis no replay for the error?

Can any one tell me the reason?

 

| | Comments (4) | TrackBacks (0)

itext果然是个好东西,虽然很是复杂,但是使用起来确是很好,很弓虽大!

《itext in action》写的很是详细,看了其中的一个分割pdf的类,修改了一下。

参数2个,tag file-you-want-split.pdf

/**
 * pdf split tools
 * @author 2hei.net
 */

package com.2hei.net.pdftools;


import java.io.*;
import java.util.List;
import java.util.Date;
import java.util.ArrayList;
import java.util.Iterator;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.SimpleBookmark;

public class Main extends java.lang.Object {
   
    public static void main(String[] args)
    {
        if (args.length < 2)
        {
            System.err.println("参数 error ");
        }
        else
        {
            // split pdf
            if(args[0].equals("1"))
            {  
                StringBuffer path = new StringBuffer();
                for(int i = 0 ;i< args[1].split("\\.")[0].split("\\\\").length-1;i++)
                {
                    path.append(args[1].split("\\.")[0].split("\\\\")[i]+"\\");
                }              
               
                try {
                        int pagenumber = 0;
                        // we create a reader for a certain document
                        PdfReader reader = new PdfReader(args[1]);
                        // we retrieve the total number of pages
                        int n = reader.getNumberOfPages();
                        System.out.println("");
                        for(int i=1;i<=n;i++)
                        {
                            Document document = new Document(reader.getPageSizeWithRotation(i));
                            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path+"\\A"+i+".pdf"));
                            document.open();
                            PdfContentByte cb = writer.getDirectContent();
                            PdfImportedPage page;
                            document.setPageSize(reader.getPageSizeWithRotation(i));
                            page = writer.getImportedPage(reader, i);                       
                            int rotation;
                            rotation = reader.getPageRotation(i);
                            if (rotation == 90 || rotation == 270) {
                                    cb.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).getHeight());
                            }
                            else {
                                    cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
                            }
                            document.close();                           
                        }  
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }

      }

}

| | Comments (0) | TrackBacks (0)

关于本篇存档

本页是归档于分类java

上一分类:IT

下一分类:linux

回到首页 或者查看归档文章

  • Powered by FeedBurner
  • Add to Google Reader or Homepage
  • Add to My AOL
  • Subscribe in NewsGator Online
  • del.icio.us/2heidel.icio.us/2hei
  • Subscribe to feed feeds