ITeye博客

javase

共 19 篇文章

抓取解析ip并入库

[list] [*]以下代码为抓取ip地址并入库分析,代码仅供参考,并未做任何处理.... public static void main(String[] args) { String crawl_url = "http://www.cnblogs.com/xioxu/archive/2009/05/03/1448322.html"; StringBuilder sb = new StringBuilder(); try{ URL instance = new URL(crawl_url); URLConnection con = instance.openConnection(); Bu…

2012-06-21 11:49 · javase

java ip转换

代码仅供参考,没做任何异常处理.. public static void main(String args) { String ip = "127.0.0.1"; String toArray = ip.split("\."); long ipToLong = 0L; ipToLong = ((Long.parseLong(toArray)) << 24) + (Long.parseLong(toArray) << 16) + (Long.parseLong(toArray) << 8) + (Long.parseLong(toArray)); System.out.println("ipT…

2012-06-11 19:25 · javase

tune app performance

为什么要写这篇文章,是因为最近线上product出现的性能问题因为上次的发布而引起巨大的波动,cpu使用率从日常的20%左右一下飚升到了最高能达到80%,load值从平常的2左右飚升到10,这个数字我想不管是对于开发、dba、sa来说如果碰到这样的事情,我想心情至少下降好几个等级,这意味着产品存在很严重的问题,那必然接下是花时间去解决掉问题,但是因为这次的发布全是因为web app所致,于是最紧迫的工作就是赶快抓紧时间去分析解决问题的思路和方法. 我先对这个系统做一个大概的概述,首先主站会发出一个search request,到后端以后会组装成wrapper list,然后通过AMQ通道来发…

2011-11-10 00:08 · javase

java字符统计

之前看到几个迅雷的上机题,于是在空闲之余写了一个简单的测试:(代码测试通过,如果需要应用到时间项目中需要对异常处理进行处理,也仅代表个人观点,仅供参考,欢迎大家提出更优解决方案) // 统计文件中指定字符出现个数和位置以及在文件中的行数 BufferedReader in = null; int count = 0; int line = 0; try{ File f = new File("E:\\ftp.txt"); in = new BufferedReader(new InputStreamReader(new FileInputStream(f))); String readLin…

2011-01-04 16:03 · javase · C · Java · C++ · C# · F#

Linux jdk环境变量及端口开放

附件是Linux jdk搭建以及简介。有问题欢迎来信讨论..

2010-12-16 16:33 · javase · Java · Linux · JDK

java实现每一个小时创建一个文件夹

在开发的过程中如果一个项目的访问量很大的时候我们可能需要对项目的日志做一个分析,从而会产生一个需求那就可能是需要把日志按小时来分类存储(也就是日志每一个小时产生一个文件夹并每一小时产生一个文件这样的话有利于日后的日志分析工作),但是这样的实现并不困难方法很多,可是直接使用java.util.TimeTask来实现,只要设置period的时间段为自己想设置的时间段就可以,但同时也可以直接用quartz定时程序来实现。我这边只是写了一个测试程序来实现该功能,使用的Thread来实现.(以下代码仅供参考) public class Test implements Runnable { privat…

2010-11-22 10:33 · javase · Java · quartz · 工作 · Web · thread

jstat使用浅谈

jstat是jdk自带的一个命令,在jdk安装目录bin目录下,使用该工具可以进行java一些性能调优 Option Displays... class Statistics on the behavior of the class loader. compiler Statistics of the behavior of the HotSpot Just-in-Time compiler. gc Statistics of the behavior of the garbage collected heap. gccapacity Statistics of the capacities…

2010-11-19 10:57 · javase · HTML · Oracle · JDK

java获取项目物理路径

测试只在windows底下,基于Linux没测试.. private String getContextPath(){ String contextPath = this.getClass().getResource("/").toString().replace("/", "\\\\"); contextPath = contextPath.substring(contextPath.indexOf("\\")+2,contextPath.length()); return contextPath; }

2010-11-10 15:12 · javase · Java · Windows · Linux

获取指定时间断系统时间

package com.vodone.subwayzero.util; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Test { public static void main(String[] args)throws Exception{ Calendar begin = new GregorianCalendar(); Calendar end = new Grego…

2010-09-27 15:38 · javase · Java

求素数

public class PrimeDemo { static int primeCount = 0; public static void main(String[] args){ int num = 100; System.out.println(num + "以内的素数:"); for(int i=3;i<=num;i++){ int tempCount = 0; if(!isPrime(i,tempCount)){ ++ primeCount; System.out.print(i + "\t"); } tempCount = 0; } System.out.println("\n1…

2010-06-25 18:37 · javase

选择排序

public class SelectSort { public static void main(String[] args){ int[] a = new int[]{52,254,10,2,5,25,89}; int[] rs = selectSort(a); System.out.println("arraysResult:"); for(int i=0;i<rs.length;i++){ System.out.print(rs[i] + "\t"); } } private static int[] selectSort(int[] arr) { int arrLen = arr.…

2010-06-13 17:57 · javase · Java · J#

插入排序

public class InsertSort { public static void main(String[] args){ int[] a = new int[]{52,254,21,10,2,5,89}; int[] rs = swap(a); System.out.println("arraysResult:"); for(int i=0;i<rs.length;i++){ System.out.print(rs[i] + "\t"); } } private static int[] swap(int[] a){ for(int i=1;i<a.length;i++){ int…

2010-06-13 17:51 · javase · Java

Math

Math类中提供了三个与取整有关的方法:ceil、floor、round,这些方法的作用与它们的英文名称的含义相对应,例如,ceil的英文意义是天花板,该方法就表示向上取整,Math.ceil(11.3)的结果为12,Math.ceil(-11.3)的结果是-11;floor的英文意义是地板,该方法就表示向下取整,Math.ceil(11.6)的结果为11,Math.ceil(-11.6)的结果是-12;最难掌握的是round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.…

2010-05-20 17:03 · javase · 算法

堆栈浅析

public class Stack { long[] stackArr; int nEleme; int top; // initialization public Stack(int n){ this.nEleme = n; stackArr = new long[this.nEleme]; top = -1; } // isEmpty public boolean isEmpty(){ return (top == -1) ? true : false; } // push public void push(int value){ if(isFull()) return; stackA…

2010-05-18 14:48 · javase

冒泡排序

private static int bubbleSort(int a){ for(int k=0;k<a.length;k++){ for(int i=0;i<a.length;i++){ if(a < a*){ int temp = 0; temp = a*; a* = a; a = temp; } } } return a; } 其数据项移动次数为(n*(n-1)/2)

2010-05-18 13:21 · javase

ThreadPoolExecutor浅谈(转)

一直都是使用Executors.newFixedThreadPool(10)这样的方式来创建线程池。 这个工厂方法实际创建ThreadPoolExecutor对象,其构造函数有三个主要参数 corePoolSize maximumPoolSize 和workQueue newFixedThreadPool的时候ThreadPoolExecutor的三个构造参数分别为10,10,new LinkedBlockingQueue(); 一直都错误地理解 他的工作方式,及新加入一个任务后,如果当前线程数达到maximumPoolSize后,就放入队列中等待执行。 想当然地认为只要参数设置为1,10,…

2010-02-04 11:03 · javase · 工作 · Web

java堆栈浅谈

在java中,对象和成员变量、静态变量这些属性多属于对象本身(通常也成为类),对象、成员变量、静态变量多是存储在内存堆中。而方法和局部变量多是存储在栈中,栈存放的顺序是先进后出(队列的顺序是先进先出)。在系统启动以后,JVM会自动注册到系统,然后分配一段内存区域。

2010-01-29 13:24 · javase · Java · JVM

java反射

1、实例化当前javabean类 2、获取当前javabean类的所有成员变量. 3、设置set或者get方法 4、获取javabean成员变量类型 5、方法注入 public class HttpUtil { public static Object getParameterValue(HttpServletRequest request,String ECID){ Object obj = null; try{ obj = Class.forName(ECID).newInstance(); Class classType = obj.getClass(); // get all fie…

2010-01-26 16:05 · javase · Java

java访问修饰符详解

下面详细介绍一下(public、private、protected、缺省) 1、public:所有的类多可以访问该类中的成员变量和方法. 2、private:该修饰符修饰的方法和成员变量只能在在当前类中使用,不能跨包也不能跨类使用该修饰定义的成员变量和方法. 3、protected:该修饰符修饰的成员变量和方法使用范围包括本类、本包、及其子类. 4、缺省修饰符:该修饰符修饰的成员变量和方法使用范围包括本类和本包.

2010-01-23 16:50 · javase · Java