11 2012 档案
摘要:1.单线程实现package com.mime; import java.io.File; public class TotalFileSizeSequential { private long getTotalSizeOfFilesInDir(final File file) { if (file.isFile()) return file.length(); final File[] children = file.listFiles(); long total = 0; if (children != null) for (final File chil...
阅读全文
摘要:我们先看下面一个示例 public class RaceCondition { private static boolean done; public static void main(final String[] args) throws InterruptedException { new Thread(new Runnable() { public void run() { int i = 0; while (!done) { i++; } System.out.println("Done!"); } }).start...
阅读全文
摘要:public abstract class AbstractPrimeFinder { public boolean isPrime(final int number) { if (number <= 1) return false; for (int i = 2; i <= Math.sqrt(number); i++) if (number % i == 0) return false; return true; } public int countPrimesInRange(final int lower, final int upper) { ...
阅读全文
摘要:字典树查找,Trie,又称字典树、单词查找树,是一种树形结构,用于保存大量的字符串。它的优点是:利用字符串的公共前缀来节约存储空间。package com.jwetherell.algorithms.data_structures; import java.util.Arrays; /** * A trie, or prefix tree, is an ordered tree data structure that is used to * store an associative array where the keys are usually strings. * * =...
阅读全文
摘要:区间树可以统计某个区间对应的重复的区间package com.jwetherell.algorithms.data_structures; import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet; /** * An interval tree ...
阅读全文
摘要:1.到这里下载apache的最新版2.4.3http://httpd.apache.org/download.cgi#apache242.先安装apache需要的几个模块下载所需软件包:
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip 具体步骤如下...
阅读全文
摘要:最近重新学习数据结构和算法,刚刚看完java版的这几个数据结构,比较浅显易懂,有兴趣的可以自己去调试学习,关于这几个的介绍网上很多。二叉搜索树,比较简单的树结构了package com.jwetherell.algorithms.data_structures; import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Queue; /** * A binary search tree (BST), wh...
阅读全文
摘要:1.到mysql网站下载mysql cluster版本http://www.mysql.com/downloads/cluster/ 下载到/home/weijianzhongwj/software下2.安装mysql clustercd /home/weijianzhongwj/software tar xvfmysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz ln -smysql-cluster-gpl-7.2.8-linux2.6-i686 mysqlc在$HOME/.bashrc增加 export PATH=$PATH:/home/weijianz
阅读全文
摘要:我使用的ubutun,安装用apt-get非常方便。weijianzhongwj@ubuntu:~$ dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw 16 5 77 2 0 1| 181k 147k| 0 ...
阅读全文
摘要:public OfferInfo parseXml(String content) throws NumberFormatException, XMLStreamException { if (content == null || content.isEmpty()) { return null; } XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = null; try ...
阅读全文
摘要:1.先去hadoop官网下载hadoop的源码http://svn.apache.org/repos/asf/hadoop/common/trunk2.下载maven3,当前hadoop的最新版必须使用maven3编译3.到hadoop下载源码目录执行mvn clean install;mvn eclipse:eclipse;4.将源码导入eclipse;5.在eclipse设置执行的WordCount.java的jvm启动参数,最少需要两个,输入目录和输出目录6.然后就可以设置断点进行调试了,我们在处理mapreduce的主干流程上设置断点org.apache.hadoop.mapred.L
阅读全文
摘要:在Arrays.java中的sort中 public static void sort(Object[] a, int fromIndex, int toIndex) { if (LegacyMergeSort.userRequested) legacyMergeSort(a, fromIndex, toIndex); else ComparableTimSort.sort(a, fromIndex, toIndex); } /** To be removed in a future rel...
阅读全文
摘要:/* * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * publishe...
阅读全文
摘要:在java中可能很多人都会忽略数据结构(类似树,跳跃表等),大家都比较熟悉链表,数组,栈,队列,哈希表等。最近看了jdk中关于树和跳跃表等的实现,其实数据结构真的是基础,有兴趣的java程序员可以翻开jdk的代码仔细阅读下面几种数据结构的学习。TreeMap:红黑树http://v.163.com/movie/2010/12/9/J/M6UTT5U0I_M6V2TJ49J.html这里有网易公开课的教学视频PriorityQueue:最小堆比较简单的一种实现,queue[n]的左右儿子是queue[2*n+1]和queue[2*n+2],每次根据排序类取第一个queue[0],然后把queue
阅读全文