Skip to main content

Posts

Showing posts from 2012

特殊字符

下面的表格列出了其余的特殊字符,这些特殊字符都可以使用反斜杠来添加到文本字符串中: 代码 输出 \' 单引号 \" 双引号 \& 和号 \\ 反斜杠 \n 换行符 \r 回车符 \t 制表符 \b 退格符 \f 换页符

Java堆内存的10个要点

From  http://sd.csdn.net/a/20120220/311988.html 导读:对于程序员来说,知道堆空间,设置堆空间,处理堆空间的outOfMemoryError错误,分析heap dump是非常重要的。文中介绍了Java堆的学习教程以及Java堆内存(heap memory)的十个要点。 文章内容如下: 我刚开始学习Java编程时,可不知道什么是堆内存或堆空间(heap space),甚至根本不管对象创建时都放在哪里去了。正式了写一些程序后,经常会遇到java.lang.outOfMemoryError等错误,我才开始关注堆内存。 对大多数 程序员 都经历过这样的过程,因为学习一种语言是非常容易来的,但是学习基础是非常难的,因为没有什么特定的流程让你学习编程的每个基础,使你发觉编程的秘诀。 对于程序员来说,知道堆空间,设置堆空间,处理堆空间的outOfMemoryError错误,分析heap dump是非常重要的。这个关于Java堆的教程是给我刚开始学编程的兄弟看的。如果你知道这个基础知识或者知道底层发生了什么,当然可能帮助不是那么大。除非你知道了对象被创建在堆中,否则你不会意识到OutOfMemoryError是发生在堆空间中的。我尽可能的将我所知道的所有关于堆的知识都写下来了,也希望你们能够尽可能多的贡献和分享你的知识,以便可以让其他人也受益。 Java中的堆空间是什么? 当Java程序开始运行时,JVM会从操作系统获取一些内存。JVM使用这些内存,这些内存的一部分就是堆内存。堆内存通常在存储地址的底层,向上排列。当一个对象通过new关键字或通过其他方式创建后,对象从堆中获得内存。当对象不再使用了,被当做垃圾回收掉后,这些内存又重新回到堆内存中。要学习垃圾回收,请阅读”Java中垃圾回收的工作原理”。 如何增加Java堆空间 在大多数32位机、Sun的JVM上,Java的堆空间默认的大小为128MB,但也有例外,例如在32未Solaris操作系统(SPARC平台版本)上,默认的最大堆空间和起始堆空间大小为 -Xms=3670K 和 -Xmx=64M。对于64位操作系统,一般堆空间大小增加约30%。但你使用Java 1.5的throughput垃圾回收器,默认最大的堆大小为物理内存的四分...

CronJob

Example Example: Insert a record into a database every one minute. 1. Create a .sh file ----insertsms.sh--- mysql -N -u root -e "use database; INSERT INTO table1 (project_id,feedback_id, text)VALUES (5,201,'Thank you,  I am ALWAYS happy with the service I receive from .......');" 2. Run command in the command line # crontab -e 3.   Append the following entry: 0-59 * * * * /root/ insertsms  .sh save the file More Examples To run /path/to/command five minutes after midnight, every day, enter: 5 0 * * * /path/to/command Run /path/to/script.sh at 2:15pm on the first of every month, enter: 15 14 1 * * /path/to/script.sh Run /scripts/phpscript.php at 10 pm on weekdays, enter: 0 22 * * 1-5 /scripts/phpscript.php Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter: 23 0-23/2 * * * /root/scripts/perl/perlscript.pl Run /path/to/unixcommand at 5 after 4 every Sunday, enter: 5 4 * * sun /p...

How to install JSVC on Linux WidenHome Log | WidenHome Log

How to install JSVC on Linux WidenHome Log | WidenHome Log In our team, we have a lot of Java standalone applications which should be run as daemon on Unix/Linux system, and we found JSVC is the best choice for us to wrap Java programs to daemons. This article records the steps on how to install JSVC executable on Linux, which is our stage/prod environment. Download JSVC source package First of all, we need to download JSVC source package from this URL: http://commons.apache.org/daemon/download_daemon.cgi , for example, I downloaded commons-daemon-1.0.5-src.tar.gz file. Or, download it via wget: wget -c http://apache.etoak.com/commons/daemon/source/commons-daemon-1.0.5-src.tar.gz Build JSVC executable Unzip the source package and build JSVC executable. chmod 755 commons-daemon-1.0.5-src.tar.gz tar zxvf commons-daemon-1.0.5-src.tar.gz cd commons-daemon-1.0.5-src/src/native/unix Before building the JSVC executable, please make sure you have set JAVA_HOME variable correctly. And make sur...

Log4j Configuration

First, include  Log4j   jar file in your project (e.g. log4j-1.2.8.jar) From  http://www.javabeat.net/tips/82-baisc-steps-to-configure-log4j-using-xml-and.html Configure Log4j This example demonstrated how to configure  Log4j  setup using the Proerties file and  XML file . These are the two most widely used techniques for configuring the  Log4j  for your application. But, in the recent days configuring with  properties files  are considered to be old technique and recommended using  XML . This example program uses simple satndalone java program for running the example. But, in most of the  project  scenarios it will be used in the web application. However the configuration file will be the same. log4j.properties # Set root logger level to DEBUG and its only appender to Appender1. log4j.rootLogger=INFO, Appender1,Appender2 # Appender1 is set to be a ConsoleAppender. log4j.appender.Appender1=org.apache...

org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcesso

org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor 这个错误是tomcat的lib文件夹jar包和项目的lib文件下的jar包冲突了 把项目下lib文件下和tomcat的jar的重复的全部删除。错误终于被搞定。 注意,如果你是先建flex工程然后转成web形式的,请把项目中tomcat类库删除,不然还会冲突 第二种解决办法 修改了tomcat里的context.xml文件,在context 元素下添加     

Manipulating Files in Java 7

From  Manipulating Files in Java 7 The following is a modified snippet from a draft of  The Well-Grounded Java Developer . It gives you a quick taster of how much easier it is to manipulate files in Java 7 than in previous versions. By using the new  Files  class and its many utility methods, you can perform the following operations on files with only a single line of code: Create Delete Copy Move/Rename TIP  A quick note on  Path . This post assumes you have some passing familiarity with the new Java 7  Path  class, if not here’s a quick introduction!  Path  is the logical abstraction of a location on the file system, e.g.   c:\  is a  Path  as is  ../foobar.txt Let’s start by looking at the creation and deletion of files. Creating and Deleting files By using the simple helper methods in the  Files  class you can create files and delete them easily as well. TIP  If you are runn...