共 33 篇文章 |
|
httpclient请求时遇到org.apache.http.client.ClientProtocolException.本项目中用到的第三方组件是apache的httpclient,一个非常强大的网页抓取工具(抓这个字用得可能不太好), 这里和大家 一起讨论下httpclient的一些常用用法和要注意的地方。import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.meth... 阅7499 转23 评0 公众公开 16-02-22 14:00 |
Hashtable与ConcurrentHashMap区别。ConcurrentHashMap融合了hashtable和hashmap二者的优势。但是hashtable每次同步执行的时候都要锁住整个结构。试想,原来 只能一个线程进入,现在却能同时16个写线程进入(写线程才需要锁定,而读线程几乎不受限制,之后会提到),并发性的提升是显而易见的。而在迭代时,ConcurrentHashMap使用了不同于传统... 阅146 转0 评0 公众公开 16-02-20 18:38 |
HashMap解决hash冲突的方法。上面方法的代码很简单,但其中包含了一个设计:系统总是将新添加的 Entry 对象放入 table 数组的 bucketIndex 索引处——如果 bucketIndex 索引处已经有了一个 Entry 对象,那新添加的 Entry 对象指向原有的 Entry 对象(产生一个 Entry 链),如果 bucketIndex 索引处没有 Entry 对象,也就是上面程序代码的 e 变... 阅1592 转2 评0 公众公开 16-02-20 18:38 |
“你知道HashMap的工作原理吗?” “你知道HashMap的get()方法的工作原理吗?”但一些面试者可能可以给出答案,“HashMap是基于hashing的原理,我们使用put(key, value)存储对象到HashMap中,使用get(key)从HashMap中获取对象。当我们给put()方法传递键和值时,我们先对键调用hashCode()方法,返回的hashCode用于找到bucket位置来储存Entry对象... 阅23 转1 评0 公众公开 16-02-20 18:26 |
注解@PostConstruct与@PreDestroy讲解及实例。被@PostConstruct修饰的方法会在服务器加载Servle的时候运行,并且只会被服务器执行一次。import com.whaty.framework.cache.entitycache.service./** * @author bc_qi * @param <KEY> * @param <ENTITY> */ @Service("AjaxCacheableService") public class AjaxCache... 阅62 转0 评0 公众公开 15-06-23 14:39 |
Java代码 package test5; public class MyTest { public static void main(String[] args) { Outer outer=new Outer("test"); Outer.Inner inner = outer.new Inner(20); } } class Outer{ Outer(String str){ } protected class Inner{ public Inner(int a){ ... 阅38 转0 评0 公众公开 15-06-17 10:23 |
关于Java的File.separator.比如说要在temp目录下建立一个test.txt文件,在Windows下应该这么写:File file1 = new File ("C:\tmp\test.txt");在Linux下则是这样的:File file2 = new File ("/tmp/test.txt");如果要考虑跨平台,则最好是这么写:File myFile = new File("C:" + File.separator + "tmp"... 阅2056 转4 评0 公众公开 15-06-16 18:20 |
Java NIO系列教程(五) 通道之间的数据传输 | 并发编程网。在Java NIO中,如果两个通道中有一个是FileChannel,那你可以直接将数据从一个channel(译者注:channel中文常译作通道)传输到另外一个channel。FileChannel的transferFrom()方法可以将数据从源通道传输到FileChannel中(译者注:这个方法在JDK文档中的解释为将字节从给定的可读取字... 阅39 转1 评0 公众公开 15-06-12 18:49 |
Java RandomAccessFile用法RandomAccessFile.//以下演示文件复制操作 System.out.println("——————文件复制(从file到fileCopy)——————"); file.seek(0); RandomAccessFile fileCopy=new RandomAccessFile("fileCopy","rw"); int len=(int)file.length();//取得文件长度(字节数) ... 阅59 转0 评0 公众公开 15-06-12 18:36 |
Java NIO系列教程(四) Scatter/Gather | 并发编程网。聚集(gather)写入Channel是指在写操作时将多个buffer的数据写入同一个Channel,因此,Channel 将多个Buffer中的数据“聚集(gather)”后发送到Channel。Scattering ReadsScattering Reads是指数据从一个channel读取到多个buffer中。read()方法按照buffer在数组中的顺序将从channel中读... 阅37 转1 评0 公众公开 15-06-12 09:58 |