Results tagged “java” from WHO IS 2HEI?

#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)

 

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)

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)

Name & Version

NSIcom CrEme 3.2.2

SavaJe OS 2.0

Sun Personal Java

Blackdown J2RE (ARM port)

Esemertec Jeode

IBM WebSphere Studio

Supported OS

CE.net, PocketPC/2002

-

WinCE 2.11

Familiar Linux

WinCE 2.11, PocketPC,
Linux

WinCE 2.11, PocketPC

JVM Compatibility

PersonalJava compliant

J2ME MIDP 2.0

PersonalJava compliant

Java 2 (1.3.1)

PersonalJava compliant

J2ME MIDP 1.0

Speed

Fast

Very fast

Fast

Slow start, reasonable execution.

Fast

Fast (Ahead of time compile)

Additional Supported Packages 

SWING COMM, CORBA, SQL, JSSE

SWING, JINI, COMM

-

All available under Linux

-

-

Supported Hardware

PocketPC/ARM, Palm, HPC

PocketPC/ARM

MIPS, SH3

iPAQ H36xx  (or better)

Dell Axim X5

PocketPC/ARM,WinCE, PalmOS, Windows, Wind River..

Cost

Contact NSIcom

Contact SavaJe

Free - Sun EOL

Free

$49.95 from Handango

Web site

 

Name & Version

Ewe VM

SuperWaba VM

Kada

Hewlett Packard ChaiVM

Supported OS

Linux, PocketPC/2002, Windows, Palm, HPC Pro

PocketPC, Palm

WinCE 2.11/3.0

Familiar Linux
PocketPC

WinCE 2.11, PocketPC

JVM Compatibility

PersonalJava compliant,
Java 1.1, Java 1.2

Check web site

J2ME MIDP 2.0

Kaffe
PersonalJava compliant

PersonalJava compliant

Speed

Medium-Fast

Medium

Fast (Ahead of time compile)

-
-

Slow

Additional Supported Packages 

Waba, ActiveSync

Waba

J2ME, PersonalJava

Kaffe (AWT, J2SE)
-

-

Supported Hardware

PocketPC/ARM, Sharp Zaurus, Palm, HPC, Linux, Win32

 

PocketPC/ARM, Palm

PocketPC/ARM

PocketPC/ARM PocketPC/ARM

PocketPC/ARM

Cost

Free

Free

Contact Kada

Free
$19.95

Free

(Note: '-' in a cell indicates this information is unknown or unavailable, please contact us if you can help)

 

SavaJe XE

Description: Fully featured Native Java OS
Notes: PocketPC port was recently sold to  recently sold to MochaWorks who have not released anything yet. Early versions demonstrated a Java OS with neat UI, MP3 player, organizer etc with support for PC card 802.11, CF & PC card Ethernet and MODEM.
URL: http://www.mochaworks.com

Sun PersonalJava

Description: Sun抯 own Java runtime environment for handhelds.
Notes: This product has been discontinued, though a CE 2.11 version is available from Sun's EOL(End Of Life) site. Fairly fast and well implemented, AWT components look same as those on desktop machines, a useful console window is provided for debugging etc, is also very well documented and supported. Only problem is that it does not manage memory or threads very well, command line options can be used to help slightly (by assigning more memory), though many simultaneous threads and large data structures always cause a crash.
URL: http://java.sun.com/products/personaljava/index.html

 

Blackdown J2RE

 

Description: Blackdown's Java 2 JDK for Linux ported to ARM

Notes: Requires Linux on iPAQ

URL: http://www.blackdown.org/

 

Jeode

 

Description: Well featured PocketPC VM

Notes: Comes free with some Compaq iPAQs (this version is limited to iPAQ devices only). Also available for Dell PDA's from Handango. The only other way I found to purchase Jeode is to join their educational institution program, which seems very expensive.

URL - http://www.esmertec.com

 

NSICOM CrEme

 

Description: Quick, good support, very polished - an excellent product
Notes - Handles memory far better than Sun's Personal Java, also faster. Supports Truffle and Tiny AWT AWT components which all work perfectly, it is provided with a useful launcher application.  Provides various useful command line switches (such as to remove WinCE task bar), comm support fully implemented & works perfectly (also tested with iButtons). Overall a very solid VM implementation.

URL: http://www.nsicom.com/

 

IBM WebSphere Studio

 

Description: VM is provided as part of Java development suite for embedded devices.

Notes: Commercial product, though Linux evaluation version are available for download

URL: http://www.ibm.com/websphere

 

Ewe VM

 

Description: An open source, free JVM with Active Sync toolkit. It is based on the popular Waba API www.wabasoft.com but extended to embrace the PocketPC.

Notes: Runs fast, stable, and the developer is very responsive to support questions.

URL: http://www.ewesoft.com

 

SuperWaba VM

 

Description: Another free JVM based on the Waba API, with support for both PalmOS and PocketPC with almost 100% source compatibility between the two platforms.

Notes: A lot of good GUI tools and libraries to extend the API to the platform.

URL: http://www.superwaba.com.br

 

Kaffe

 

Description: Clean room unlicensed (but legal) Java VM implementation.

Notes: Implementation is not complete and contains bugs.

URL: http://www.kaffe.org

 

jCompiler

 

Description: This is a Java IDE/compiler which runs on the PocketPC!
Notes: Doesn't seem to be an official web site, contact jCompiler@hotmail.com for more info.

URL: [Handango Link]

 

Kada

 

Description: A commercial JVM for Palm and Pocket PC. It supports the J2ME programming model and Kada is the first to offer a MIDP 2.0 release.

Notes: They offer an ahead of time (AOT) compiler to improve efficiency.

URL: http://www.kadasystems.com

 

 

Hewlett Packard ChaiVM

 

Description: HP's own clean room JVM implementation. Provided with its Jornada range of devices. No recent activity/releases.
Notes: Slow and slightly buggy implementation. Provided native compiler.

URL: http://www.hp.com

 

Another site you might might useful is Vik David's page Java on PocketPC, the Unofficial FAQ  

 

This page was last updated on 20/6/03 by Dan Fitton (df (at) comp.lancs.ac.uk) with much help from Rod Montrose (rcm (at) avidwireless.com)

| | Comments (0) | TrackBacks (0)

一些 Java decompilers 反编译工具


jad工具在使用时有如下错误的解决:

如:

E:\2hei.net\src\>jad -sjava HelloWorld.class
Parsing HelloWorld.class...The class file version is 48.0 (only 45.3 and 46.0 are supported)
JavaClassFileParseException: Class file version mismatch

可以使用UE编辑class文件。把class文件的第八个字节30或者31修改为2E,再使用jad反编译即可。

推荐使用DJ,可视化的界面,比较方便,默认是生成了后缀为jad的java源文件。

dj.jpg

 DJ 3.9.9的版本已经需要注册。老版本的还可以正常使用。

 

| | Comments (0) | TrackBacks (0)

java 访问url ,可以使用类似IE中设置的代理服务器进行访问。

java的net包里面就有proxy类,通过这个类进行代理设置,在程序对url进行访问之前调用这个方法即可。

    public static void ProxySet()
    {
        Properties sys = System.getProperties();
        sys.put("proxySet", "true");
        sys.put("proxyHost", "61.19.148.233");//代理服务器ip
        sys.put("proxyPort", "8080");//代理服务器端口
        System.setProperties(sys);
    }
    
    
   

| | Comments (0) | TrackBacks (0)

 

1. Introduction

edtFTPj/Free is the most popular Java FTP client library available today. Robust, fast and with an extensive API, it provides a solid foundation for developers who require FTP functionality in their Java applications. Full source code is included.

This document provides an overview of the package and links to documentation and examples.

2. Features

edtFTPj/Free's many features include:

  • Rock-solid FTP transfers.
  • Passive and active modes are supported (PASV and PORT).
  • Resuming of interrupted binary transfers supported.
  • Progress monitoring of data transfers.
  • FTP streams

 

主页如下: http://www.enterprisedt.com/products/edtftpj/overview.html

edtFTPj是一个FTP客户端包它可以嵌入到应用程序中以便以提供FTP的功能.它提供一些方法如:put(),get(),chdir(),dir()与pwd()等来完成FTP的功能。

API讲的比较详细,其提供的ftp传输包括文件和流的方式比较方便,并且在远程目录的处理上有自己的独到之处。

强烈推荐使用。

 

 

 

| | Comments (1) | TrackBacks (0)

标签